Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 6 months ago.
I2C communication blocked between master and slave [NUCLEO boards]
Hello everyone, I'm trying to make 2 boards communicate but I'm facing an issue. After the second byte is sent no ack is received so the communication stops, how can i solve this?
Here is the master code:
- include "mbed.h"
I2C i2c(PB_9,PB_8); sda, scl Serial pc(PA_2, PA_3);
const int addr = 0x78; define the I2C Address
int main() { char cmd[2]; pc.printf("INIXI"); i2c.frequency(100000); while(1) { i2c.write(addr, "xyz", 3); wait(1); } }
Here is the slave:
- include "mbed.h"
I2CSlave slave(PB_9,PB_8); Serial pc(PA_2, PA_3); DigitalOut led1(LED1);
int main() { pc.printf("Welcome\n"); char buf[8] = {0}; char msg[] = "AHK"; int val;
slave.frequency(100000); slave.address(0x78); pc.printf("Starting program"); while (1) { int i = slave.receive(); if(i == 0) continue; pc.printf("Slave Receive: %d: \n", i); switch (i) { case I2CSlave::ReadAddressed: val = slave.write(buf, 4); Includes null char pc.printf("ReadAddressed: %d\n\r", val); break; case I2CSlave::WriteGeneral: val = slave.read(buf, 4); pc.printf("WriteGeneral: %d\n\r", val); break; case I2CSlave::WriteAddressed: val = slave.read(buf, 6); pc.printf("WriteAdressed: %s\n\r", buf); for(int i = 0; i < 8; i ++) { pc.printf(" %d \t ", buf[i]); } break; } } }
MASTER: NUCLEO-F446RE SLAVE : NUCLEO-L476RG