7

If you have a read of section 31 of the Datasheet, available from here, things may come a little clearer for you. Here's a summary of what I know: PIO stands for Parallel Input/Output and offers the functionality to read and write multiple register ports at a time. Where the datasheet mentions a register, for example PIO_OWER, the Arduino library has ...


5

This code sends a pulse on pin PB0, which on the Uno is equivalent to digital 8. On the Mega, digital 8 is PH5, thus you would write PORTH |= _BV(PH5); PORTH &= ~_BV(PH5); The equivalence between the Arduino pins and the AVR pins is provided in the official documentation, but there are nicer versions at pighixxx.com: Uno pinout Mega pinout


5

It's not RX1 and TX0 but RXI and TXO That is receive input and transmit output, Exactly the same as RX and TX just with the data direction explicitly shown in the lettering.


5

What is the problem in this code? No problem, it does change the bits of port D and B from 0B10101000 and 0B00101010 to 0B01010000 and 0B00010101 respectively. However, microseconds later loop() runs again and changes them back to 0B10101000 and 0B00101010 for a full second. To better see what's happening, add a second delay(1000); statement, placing it ...


4

If you compile the code and examine the results you can see how many instructions it will take, and thus how many clock cycles. It's slightly more complex because of what else happens in main() to call loop, but basically you have: for (;;) { loop(); aa:0e 94 49 00 call 0x92; 0x92 <loop> if (serialEventRun) serialEventRun(); ae:20 97 sbi ...


4

Yes. You need to create new unique names for them using udev rules. By using the unique serial number, along with the VID and PID of the board you can use udev to create a symbolic link to a device name of your choice. Best to keep it to something that the Arduino IDE recognises if you want to access the link from within there for programming (otherwise you ...


4

One (the lower number) is the IO port address which is used when using the IN or OUT op-code. The other (higher number) is the memory mapped address. Different methods of access are more programatically efficient depending on how you are manipulating the values. For instance IN and OUT are more efficient at setting or reading the entire register value, but ...


4

Yes, the ports of an Uno are addressed in C/C++ as PORTB, PORTC, and PORTD respectively, each 8 bits wide. You can read them or assign to them. Other processors' ports have similar names. Of course the pins' port assignments and functions differ from one to the other, which is one reason for providing the single-pin pinMode() and digitalRead(), digitalWrite()...


4

Your timing seems reasonable. At a rough guess, without actually compiling it, your code will turn into something along the lines of: IN R24,PORTD ;First read - temp = PORTD - 1 cycle ST X+, R24 ;First store - buffer[0] = temp - 2 cycle IN R24,PORTD ;Second read - temp = PORTD - 1 cycle ST X+, R24 ;Second store - buffer[1] = temp - 2 ...


4

The other answer has provided correct information and useful documentation on the question as asked. This answer uses a slightly more portable method of producing a brief pulse on a given digital pin. This more-portable method uses some standard (although not well-documented at arduino.cc) functions to get port numbers, port pointers, and bit masks from ...


4

Unlike most Arduinos, the ESP8266 doesn't have a hardware TWI, so I²C is bit-banged in software. This means that you can use any GPIO pins. By default, Wire.begin() initializes pins 4 (SDA) and 5 (SCL), but you can specify other pins using Wire.begin(int sda, int scl). Documentation (Note: the datasheet specifies GPIO2 as SDA and GPIO14 as SCL, but that ...


4

The tricky thing with the WeMos boards is the pin notation is different from other Arduino boards. Sometimes you will see the digital pins on Arduino boards referenced with the Dn notation. For example: "Connect the HC-SR04's Trig pin to D4 on the Uno". In fact some boards such as the Nano even use the Dn pin notation on their silkscreen. This is just a way ...


3

Because ((PIND & (1 << 2)) != LOW) means exactly (PIND & 4) != 0 and that is true if PIND is 4, 5, 6, 7, 12, 13, ... (any number having 4 in it binary), so it yelds 4 != 0 Which is definitively not equal 4 == 1 BTW: in C any integer != 0 is true and 0 is false, so you can as well write: if (PIND & (1 << 2)) PORTB |= (1 <&...


3

If you need to do more than 8 (especially LOTS more), and timing is very critical, you can use a Serial In, Parallel Out (SIPO) chip, such as the 74HC595 - it also saves a lot of pins on the Arduino. To use it, you need 3 pins connected to the Arduino. You send one bit to the chip from the Arduino for each output, then when you have them all set, you toggle ...


3

There is a fairly simple equivalence for the basic direct pin access. Below is some sample code which shows how to set a digital pin high and then low. The first is for an Arduino Due, the second is for the Arduino Uno/Mega/etc. const unsigned int imThePin = 10; //e.g. digital Pin 10 #ifdef _LIB_SAM_ //First lets get the pin and bit mask - this can be ...


3

dmesg should be the tool to help you. Run: $ dmesg -w Then hit return a few times (to get some blank lines). Next plug in your Nano. Some text should appear on the screen, which will give you a clue as to what is going on. I don't have a Nano to try with, but a typical working device would look something like: [29125.599800] usb 9-1.4.1: new full-...


3

It sounds like a blown protection diode MBR0520 in between USB and +5V of the nano.


3

SPI transmitt is started by writing one Byte into SPDR. And this code won't return from SPI_MasterTransmit function before it's complete. Transmitt completition is anounced by setting SPIF by hardware (and if SPI interrupt and global interrupts are enabled, it'll run also ISR and clear that flag). If you write into SPDR before transmission is completed you'...


3

PORTB is defined by the "toolchain". It is not defined by Arduino. For instance in my setup the Arduino Uno uses "toolchain" avr-gcc\4.9.2-amtel3.5.3-arduino2\avr. If you grep that folder (location dependent on tool and installation options) you will find a file called iom328p.h that defines #define PORTB _SFR_IO8(0x05) This is a mapping to a physical ...


3

In the boards.txt file for the core in question you have a line for each board: xxxx.build.variant=yyyy where yyyy is the name of the folder in variants for the board. For instance, the Uno, has: uno.build.variant=standard which relates to: variants/standard with the pins_arduino.h file in it for that board.


2

4 cycles: IN Rd,PORTB CBR Rd,7 ORI Rd,x OUT PORTB,Rd Translation into proper GCC inline assembly syntax is left as an exercise for the reader.


2

Your modified code doesn't disable the pullup on the pin. PORTC &= ~_BV(ADCChannel);


2

You can change the address of the GY-521 by pulling the AD0 pin to Vcc. After that the address will be 0x69 instead of 0x68.


2

I just tried compiling your code with avr-gcc 4.9.2: buffer[0] = PORTD; buffer[1] = PORTD; ... buffer[29] = PORTD; Here is what I got: in r24, 0x0b ; temp = PORTD – 1 cycle sts 0x0110, r24 ; buffer[0] = temp – 2 cycles in r24, 0x0b ; temp = PORTD – 1 cycle sts 0x0111, r24 ; buffer[1] = temp – 2 cycles ... That's 3 cycles per read, ...


2

The while loop should have no effect on interrupts. Where does run() get called? We'll need to see the code that sets up and calls the code you've shown. But as a sanity check, you could try replacing the entire contents of run() with a ;, that is make it an empty function. Then add in an empty while loop (contains only a ;, no __asm__ code) and try again. ...


2

If the other end of the link has the same signal voltage as your Arduino, you can simulate an open collector with a single pin: digitalWrite(pin, LOW); pinMode(pin, OUTPUT); sets the pin to output an active low signal. pinMode(pin, INPUT_PULLUP) sets the pin to input mode, or output passive high which, in open-collector mode, is the same thing. Note that ...


2

Each processor has different registers, things that control stuff like interrupts, input and output. I would not expect code written for one processor, especially if it directly accesses the registers, to work on another processor. You would need to look at the datasheet for the Atmega2560 and see how to control its pin change interrupts.


2

Well, I ended up answering my own question in a few minutes of forum research. You can disable the TX pin of the hardware UART with: UCSR0B &= ~bit (TXEN0);


2

You don't need an array, and your "base" pin is wrong - you start at pin 1, not pin 0. Also pins A6 and A7 can only be analog inputs, not digital outputs. It's simpler to write: void setup() { for (uint8_t i = 0; i < NUM_DIGITAL_PINS; i++) { pinMode(i, OUTPUT); digitalWrite(i, HIGH); } } void loop() { } That will work correctly ...


1

You can modify a single or multiple bits in a register by using a Read-Modify-Write approach. Essentially something like this: byte temp = DDRD; temp = (temp & ~(bitmask)) | bits_to_set; DDRD = temp; In the above code, bitmask is some value with the bit or bits you want to modify set - e.g. if you want to change bits 4 and 5, it would be (_BV(4) | _BV(...


Only top voted, non community-wiki answers of a minimum length are eligible