I2C to AVR Xmega

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
smhodge
Posts: 86
Joined: Tue Jan 22, 2019 2:16 am
Location: Kirkland, WA, USA

I2C to AVR Xmega

Post by smhodge » Fri Apr 09, 2021 12:31 am

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

User avatar
RobH
Posts: 91
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: I2C to AVR Xmega

Post by RobH » Fri Apr 09, 2021 5:52 pm

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.

smhodge
Posts: 86
Joined: Tue Jan 22, 2019 2:16 am
Location: Kirkland, WA, USA

Re: I2C to AVR Xmega

Post by smhodge » Fri Apr 09, 2021 7:56 pm

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

Post Reply