With tags I meant the code tags used by these forums: <<code>> and <</code>>
(they need to be on a newline to work). It marks up the code such as in my previous post.
Few things:
Quote:
You say the mbed works with 8 bit address. Will the IC understand? If the Sm72445 is 7 bit and mbed 8 bit, how do I get around this?
The only thing you need to do is multiply the address by 2, the R/W bit is still set by the mbed. In this case the address itself isnt the 0x10 you entered, but 0x01. I have to admit that it is quite bad the datasheet calls it 0x1 instead of 0x01. This is the 7-bit address, so you need to enter 0x02 as address (mulitplied by 2, equivalent to shifting one to the left).
Edit: The difference is in bits:
7 bit address: A6 - A5 - A4 - A3 - A2 - A1 - A0
8 bit address: A6 - A5 - A4 - A3 - A2 - A1 - A0 - R/W bit
The R/W bit is in the end set/cleared by the mbed functions, but the address must be given including that location, so the normal address shifted one position to the left.
Quote:
The edit you speak of - i2c.writes return value. This I guess would indicate that the write was successful? Like I said, I am monitoring with a scope and there is no activity on either the sda or scl lines. As far as the voltage goes. It looks correct. 3.3v on mbed side of level shifter via 10k pull ups. And 5v on Sm72445 side, also via 10k pull ups.
Indeed it shows if it was succesfull, to be precise if you receive an ACK from the device.
But it is weird you dont see anything on a scope. Only two thinks I can think of atm, with one a bit unlikely. I dont know how good (/expensive) your scope is, but can it be you are missing the communication simply because it is too short? If you remove all wait statements and also the printf it should send alot more, so much smaller chance you could miss it (it will probably depend on your scope if you could miss it in the first place).
And because you never know, you are 100% sure you connected the correct pins?
I am new to Mbed and having a problem communicating with an I2C IC. The program is very basic and compiles ok. For a start I wanted to read from one of the registers back to the uC. I am monitoring with a scope on the sda line on the uC side of a level converter I built using the recommended mosfets. I see no activity whatsoever. I did make a mistake when assembling the project board I am working with. I forgot to cut all the tracks between the two rows of pins, before switching on. I corrected the mistake and tested again. It seems to be ok, but leaves me in doubt looking at the probelm I am having with the I2C comms. Further to that I made a direct connection between it and the IC operating at 5V. That is the sda and scl lines with the required pull up resistors. I could have created further problems for myself. I did however do some reading beforehand and came to the conclusion that the mbed is 5v tolerant after reading a blog or two. Now I am not sure.
If I can get some answers I can hopefully make some progress.
The device I am trying to communicate with has 5 registers containing 7 bytes each. My code below.
The device is hardwired for address 0x1 "The command register is offset from address0xE0" - straight from the spec sheet
Please help.
I2C i2c(p9, p10); sda, scl Serial pc(USBTX, USBRX); tx, rx
const int addr = 0x10; define the I2C Address
int main() { char cmd[1]; char reg0data[7]; while (1) { cmd[0] = 0xE0; i2c.start(); i2c.write(addr, cmd, 1); i2c.read(addr, reg0data, 7); i2c.stop();
wait (0.07);
print the data to the screen float reg0byte1 = reg0data[1]; pc.printf("Register 0 Byte 1 = %.2f\r\n", reg0byte1); wait(5); } }