
Evo posto sam lijen copy/paste cu problem samo sto sam na engleskom napisao..
First of all I must to say that I googled a lot to solve my issue, but in the end I couldn't solve it so I came here to ask help.
As in the title, the problem is that my uC PIC24FJ64GB002 hangs on I2C1_Write() instruction, waiting for ACK but the address IS correct and the same code using Soft_I2C_Write() WORKS.
I tried alternative I2C pins for I2C1, I tried also I2C2 and neither worked (wiring is double checked and it's ok).
I don't have any logic analyzer or oscilloscope to see what happens but I'll leave the code here and the entire basic-project so you can look at it.
It's pretty simple.
sbit Soft_I2C_Scl at RB8_bit;
sbit Soft_I2C_Sda at RB9_bit;
sbit Soft_I2C_Scl_Direction at TRISB8_bit;
sbit Soft_I2C_Sda_Direction at TRISB9_bit;
// End Software I2C connections
char j, txt[4];
void main() {
AD1PCFG = 0xFFFF;
LATB = 0;
TRISB = 0;
LATA = 0;
TRISA = 0;
PPS_mapping(15, _INPUT, _U1RX );
PPS_Mapping(14, _OUTPUT, _U1TX);
UART1_Init(19200);
UART1_Write_Text("\nStarting..");
I2C1_Init(100000);
I2C1_Start();
I2C1_Write(0b10010000); // address TMP75 + W
I2C1_Write(0x00); // config register <= read temperature
I2C1_Restart();
I2C1_Write(0b10010001); // address TMP75 + R
j = I2C1_Read(1); // Reading 1 byte then send N_Ack(1)
I2C1_Stop();
UART1_Write_Text("\nTemperature : ");
shorttostr(j, txt);
Uart1_Write_Text(txt);
/*UART1_Write_Text("\nStarting..");
Soft_I2C_Init(); // Initialize Soft I2C communication ~20kHz
Soft_I2C_Start();
Soft_I2C_Write(0b10010000); // address TMP75 + W
Soft_I2C_Write(0x00); // config register <= read temperature
Soft_I2C_Stop();
Soft_I2C_Start();
Soft_I2C_Write(0b10010001); // address TMP75 + R
j = Soft_I2C_Read(1); // Reading 1 byte then send N_Ack(1)
Soft_I2C_Stop();
UART1_Write_Text("\nTemperature : ");
shorttostr(j, txt);
Uart1_Write_Text(txt);*/
while(1);
}
Any idea where the bug is ?
Koristim MikroC pro i stvarno ne razumem zasto kod stane na I2C1_Write() ? Ceka vjerovatno ACK od strane TMP75, ali adresa TMP75 je tacna i radi sa emulacijom I2C (Soft_I2C_Write() ).
Postavio sam isto pitanje na forumu od kompajlera pa ako tamo rijesim objavit cu i ovdje rjesenje.
Pozz
RIJESENJE MikroC dsPIC: Pin komunikacije SDA treba podesiti kao ULAZ, a ne kao IZLAZ, prije I2Cx_Init() procedure.
TRISB.B9 = 1;
[Ovu poruku je menjao sigi91 dana 19.12.2012. u 13:32 GMT+1]