??? 03/04/09 16:33 Read: times |
#163069 - i2c not working |
I'm been trying hard to communicate between 2 80552 boards, through i2c but no luck. I can see on the oscilloscope that the master is sending address on the bus, but the slave is not responding at all, he doesn't returns back acknowledge. Below are code for masters and slave. Can someone point out what mistake I'm doing. I'll be really grateful, because I've already wasted too much time on this. For the moment I've just made the code for sending address and acknowledge, so view this code from that angle.
Master ------ void i2c_initialize() { P1_6 = 1; P1_7 = 1; P1M1 |= 0xC0; P1M2 |= 0xC0; S1CON = 0x43; ES1 = 1; EA = 1; } void i2c_start (void) { S1CON = 0x43; STA = 1; transfer_status = I2C_BUSY; while (transfer_status == I2C_BUSY) ; } void i2c_isr(void) interrupt 5 using 1 { static buffer_index; i2c_int_occur = 1; switch(S1STA) { case START_TXD: STA = 0; if (i2c_read_write) S1DAT = device_address | 0x01; else S1DAT = device_address & 0xFE; break; case ADDRESS_TXD_ACK: buffer_index = 0; S1DAT = data_buffer[buffer_index]; break; case ADDRESS_TXD_NOACK: STO = 1; transfer_status = I2C_ERROR; break; } SI = 0; } void write_some (unsigned char voltage_out) { device_address = 0x90; i2c_read_write = 0; number_of_bytes = 2; data_buffer[0] = 0x40; data_buffer[1] = voltage_out; i2c_start(); } void main(void) { printf( "n"); i2c_initialize(); write_some(10); while(1) ; } In interrupt service routine, ADDRESS_TXD_NOACK case always execute, I don't know why. Following is the code for slave SLAVE ----- void i2c_initialize() { S1ADR = 0x90; S1CON |= ENS1; S1CON |= AA; } void main(void) { i2c_initialize(); while(1) ; } for the moment I just want to have acknowledge received by master, so that's why I haven't implemented anymore functionality. Now since I have set AA in S1CON, ideally the slave should acknowledge. |
Topic | Author | Date |
i2c not working | 01/01/70 00:00 | |
Can you show the definition of ENS1 and AA | 01/01/70 00:00 | |
What IDE? | 01/01/70 00:00 | |
Simulation | 01/01/70 00:00 | |
I am not familiar with this antique, but ...![]() | 01/01/70 00:00 |