vince.cimo
Well-known member
I'm stumped. I have this EEPROM device (https://datasheet.lcsc.com/szlcsc/Shanghai-Belling-BL24C04A-NTRC_C177778.pdf) hooked up to the SCL/SDA pins (18 & 19) on a Teensy LC using 4.7k external pullup resistors and am using the following test code to attempt a basic read/write operation. I can probe both the SCL and SDA pins and see that I'm getting signal on both pins, but my Serial monitor data coming back is super weird.
No errors are thrown, but sometimes the retrieved data is blank, sometimes it's garbled. I've tried numerous configurations and also tried a the basic example on the Wire library page (it hangs at while(Wire.read()) {
num = Wire.receive();
}). Where else should I look? I am at the end of the road with what I know to try.
Here's an example of the serial output from the included program:
Sending to Slave: 'Message #0' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #1' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #2' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #3' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #4' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #5' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #6' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #7' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #8' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #9' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #10' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #11' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #12' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #13' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #14' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #15' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #16' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #17' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #18' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #19' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #20' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #21' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #22' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #23' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #24' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #25' OK
No errors are thrown, but sometimes the retrieved data is blank, sometimes it's garbled. I've tried numerous configurations and also tried a the basic example on the Wire library page (it hangs at while(Wire.read()) {
num = Wire.receive();
}). Where else should I look? I am at the end of the road with what I know to try.
Here's an example of the serial output from the included program:
Sending to Slave: 'Message #0' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #1' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #2' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #3' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #4' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #5' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #6' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #7' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #8' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #9' OK
Reading from Slave: '' OK
Sending to Slave: 'Message #10' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #11' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #12' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #13' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #14' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #15' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #16' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #17' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #18' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #19' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #20' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #21' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #22' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #23' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #24' OK
Reading from Slave: 'Messaess���������>' OK
Sending to Slave: 'Message #25' OK
Code:
// -------------------------------------------------------------------------------------------
// Basic Master
// -------------------------------------------------------------------------------------------
//
// This creates a simple I2C Master device which when triggered will send/receive a text
// string to/from a Slave device. It is intended to pair with a Slave device running the
// basic_slave sketch.
//
// Pull pin12 input low to send.
// Pull pin11 input low to receive.
//
// This example code is in the public domain.
//
// -------------------------------------------------------------------------------------------
#include <i2c_t3.h>
// Memory
#define MEM_LEN 16
char inbuf[MEM_LEN];
char outbuf[MEM_LEN];
int count;
void setup()
{
// Setup for Master mode, pins 18/19, external pullups, 400kHz, 200ms default timeout
Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
Wire.setDefaultTimeout(200000); // 200ms
// Data init
count = 0;
Serial.begin(9600);
}
void loop()
{
uint8_t target = 0x50; // target Slave address
// Send string to Slave
//
// Construct data message
memset(inbuf, 0, sizeof(inbuf));
sprintf(inbuf, "Message #%d", count++);
// Print message
Serial.printf("Sending to Slave: '%s' ", inbuf);
// Transmit to Slave
Wire.beginTransmission(target); // Slave address
Wire.write(inbuf,strlen(inbuf)+1); // Write string to I2C Tx buffer (incl. string null at end)
Wire.endTransmission(); // Transmit to Slave
// Check if error occured
if(Wire.getError())
Serial.print("FAIL\n");
else
Serial.print("OK\n");
delay(1000); // Delay to space out tests
// Read string from Slave
//
// Print message
Serial.print("Reading from Slave: ");
memset(outbuf, 0, sizeof(outbuf));
// Read from Slave
Wire.requestFrom(target, (size_t)MEM_LEN); // Read from Slave (string len unknown, request full buffer)
// Check if error occured
if(Wire.getError())
Serial.print("FAIL\n");
else
{
// If no error then read Rx data into buffer and print
Wire.read(outbuf, Wire.available());
Serial.printf("'%s' OK\n",outbuf);
}
delay(1000); // Delay to space out tests
}