analogdevicesinc / msdk

Software Development Kit for Analog Device's MAX-series microcontrollers
Apache License 2.0
61 stars 82 forks source link

I2C master and slave examples on the FTH board #289

Closed marcosgatcomputer closed 1 year ago

marcosgatcomputer commented 2 years ago

Hello,

As a warming exercise for my I2C 10-bit addressing project I have been testing the master and slave examples on the Feather board and I run into an issue I would like to report.

I have tested the master example (MAX78000_SDK/Examples/MAX78000/FTH_I2C) and it works as expected. I only find this comment at the beginning of the main.c file a bit odd:

* @details     This example uses the I2C Master to read/write from/to the I2C Slave. For
 *              this example you must connect P0.10 to P0.16 (SCL) and P0.11 to P0.17 (SCL). The Master
 *              will use P0.10 and P0.11. The Slave will use P0.16 and P0.17. You must also
 *              connect the pull-up jumpers (JP21 and JP22) to the proper I/O voltage.
 */

I guess this comment was written early in the development and the layout of the board was different, but in my kit, those connections are already made in the board and I don't have any pull-up jumpers (R15 is populated with a zero ohm resistor so the bus works at 3.3V). Maybe that should be removed to avoid confusion.

I have also tried to adapt the master-slave example (MAX78000_SDK/Examples/MAX78000/I2C) to work as a slave only on the feather board removing the master parts and changing the slave to MXC_I2C1 and the interrupt vectors.

Although I'm able to compile and run the code, the behavior is not as expected. When I connect the feather board slave to a master and run i2c-detect to discover the slaves on the bus, the master reports addresses 0x18 and 0x28 which are the PMIC and audio codec on the board but the new slave I'm defining is nowhere to be found and I'm getting a lot of timeouts (the prompt once I run i2c-detect takes quite a lot to complete and I get timeout messages all over the place).

I have tried with a Raspberry Pi and a Beagle Bone Black acting as master with the same results. At first, I thought the issue was coming from the bus load/termination but I have tested several configurations with no luck.

I would be very glad to know if somebody has been able to run the FTH board as an I2C slave. I'm probably missing changing some registers or any other detail, I did not have time to look at the low-level documentation yet (I will as soon as I have the time).

One last thing I forgot to mention is that in all these tests I'm just dealing with 7-bit addresses, so no funny stuff whatsoever.

Thank you again for your help.

EDIT: Indeed my problem was in the code: I was not calling MXC_I2C_SlaveTransactionAsync(). Now the slave is detected at the address I set it up with. I'm still trying to figure out where I'm supposed to call MXC_I2C_AsyncHandler() within the ISR for the slave to keep sending data continuously (to implement a kind of a 100 byte EEPROM emulator that can be read with i2cdump).

A complete slave example similar to the master would be really nice to have. I'm keeping the issue open, I hope that's not a problem.

Regards,

Marcos

Jake-Carter commented 1 year ago

Resolved as of https://github.com/Analog-Devices-MSDK/msdk/pull/330 - the EEPROM_Emulator better demonstrates how to set the MAX78000 up as an I2C slave for this use-case