9 years, 9 months ago.

I2C loopback

Hi, I'm wondering if there's any way of getting loopback working on the LPC1768. At the moment I have pins 9,10 set up as slave and 28,27 set up as master. I have pin 9 connected to pin 28 and pin 10 connected to pin 27 with a 4.4K pull-up resistor on each line (we'd run out of 4.7K).

At the moment the code repeatedly prints "Read A:" but nothing more.

I'm assuming there is something beyond my current knowledge I need to be doing, but I don't know what that would be.

Thanks!

Attempt at i2c loopback

#include "mbed.h"    
 
Serial pc(USBTX, USBRX); // tx, rx.

I2C i2c(p28, p27);
I2CSlave slave(p9, p10);

const int addr = 0x90;
 
int main() {
    char msg[] = "Slave!";
    char buf[10];
    slave.address(addr);
     while (1) {
         i2c.write(addr, msg2, strlen(msg2)+1);
         // Slave code
         int i = slave.receive();
         switch (i) {
             case I2CSlave::ReadAddressed:
                 slave.write(msg, strlen(msg) + 1); // Includes null char
                 break;
             case I2CSlave::WriteGeneral:
                 slave.read(buf, 10);
                 pc.printf("Read G: %s\r\n", buf);
                 break;
             case I2CSlave::WriteAddressed:
                 slave.read(buf, 10);
                 pc.printf("Read A: %s\r\n", buf);
                 break;
         }
         for(int i = 0; i < 10; i++) buf[i] = 0;    // Clear buffer
     }
}
Be the first to answer this question.