Page 1 of 1

I2C to AVR Xmega

Posted: Fri Apr 09, 2021 12:31 am
by smhodge
I need to send (but not receive) packets over I2C to an AVR Xmega microcontroller, which are both on the same I2C bus. I have I2C (aka TWI in AVR jargon) master and slave code written and thoroughly tested on the Xmega, including an equivalent of the micropython scan() method. At least I assume it is the equivalent; it sends an address and checks for ACK/NACK. That scan successfully returns the (slave) address of itself (the Xmega), which is 3. In addition I know from using the debugger on it that all TWI registers are correctly set (in particular the slave module is enabled with address 3). Heck, if they weren't correct it wouldn't ping ok.

However, scan() on the pyboard does not find the Xmega, i.e., does not list address 3. It continues to list all the hardware I2C chips connected to the bus just fine, just not that of the Xmega. Both Xmega and pyboard are set to use 100 KHz.

I am assuming this is not an impossible thing to do and very probably others have done this, or to another type of micro. Any help or suggestions would be very much appreciated.

Thanks, Steve

Re: I2C to AVR Xmega

Posted: Fri Apr 09, 2021 5:52 pm
by RobH
Hi Steve,
Your choice of address may be the cause of your problem.
In I2C standards 0x00 - 0x07 and 0x78 - 0x7F are reserved I2C addresses.
Rob.

Re: I2C to AVR Xmega

Posted: Fri Apr 09, 2021 7:56 pm
by smhodge
Thanks, that solved it. Changing the Xmega slave address to 10 allowed the uPython scan() to find it.

I did some more tests and found that even if scan() does not find address 3, writeto(3,buf) still works. It returned the correct number of ACK's and the Xmega rec'd the bytes ok. The "issue" I originally posted about turns out to be just with scan().

Steve