SUPER COPTER
New Member
Hi I'm new to the forum.
I'm using a Pinguino board which has a PIC32MX440F256H microcontroller. I'm not using the Pinguino IDE, instead I'm using MPLAB with C32 compiler. I'm also using a PicKit3 programmer for loading the code to the chip.
I've been trying to make I2C bus to work with no luck.
Currently I can send bytes over the BUS, I´ve seen them whith an oscilloscope, and I get Ack's from the slave device.
I have a DS2482-100 1-Wire IC hooked up to the I2C BUS, I've made a function for writing the configuration following the steps mentioned. It (kind of) works (I recive Ack's after every command), I'm also checking the BUS's status after every step. The program gets stuck at the stop command, with a status=408. This just happens when executing the write configuration (config_status()) function, the stop command works fine in other conditions. I know status=8 means that the bus is in a START condition. Other testing before gave me error code 400 which means "Arbitration Loss" (BUS Collision). So I dont know what this 408 code would mean.
Besides that, I've been trying to read the supposed data I sould recive for checking the write configuration.
I'm using the following function to read the data:
which always returns FALSE, so it's not even executing the code inside the "if" statement. In other words, the I2CReceivedDataIsAvailable(I2C_BUS) function is returning FALSE, so I'm assuming that means the I2C read buffer is empty.
I searched the web several times to find some info about this and it seems I should be sending the slave adress before reading but, anyway, the buffer is empty so it's not even getting to that part of the code.
Here's the library I wrote for handling the Ds2482:
I I made another library with the primitive functions, but I didn't find it useful to post, unless someone asks for it. I'm using another 2 custom libraries for the DelayMs() function and for a 16x2 serial LCD (print_error() function).
Any help would be very appreciated.
I'm using a Pinguino board which has a PIC32MX440F256H microcontroller. I'm not using the Pinguino IDE, instead I'm using MPLAB with C32 compiler. I'm also using a PicKit3 programmer for loading the code to the chip.
I've been trying to make I2C bus to work with no luck.
Currently I can send bytes over the BUS, I´ve seen them whith an oscilloscope, and I get Ack's from the slave device.
I have a DS2482-100 1-Wire IC hooked up to the I2C BUS, I've made a function for writing the configuration following the steps mentioned. It (kind of) works (I recive Ack's after every command), I'm also checking the BUS's status after every step. The program gets stuck at the stop command, with a status=408. This just happens when executing the write configuration (config_status()) function, the stop command works fine in other conditions. I know status=8 means that the bus is in a START condition. Other testing before gave me error code 400 which means "Arbitration Loss" (BUS Collision). So I dont know what this 408 code would mean.
Besides that, I've been trying to read the supposed data I sould recive for checking the write configuration.
I'm using the following function to read the data:
Code:
UINT8 i2c_read_buffer(BYTE address)
{
UINT8 i2cbyte=0;
StartTransfer(0);
while ( !I2CAcknowledgeHasCompleted(I2C_BUS) );
if (I2CReceivedDataIsAvailable(I2C_BUS))
{
I2CAcknowledgeByte(I2C_BUS, TRUE);
i2cbyte = I2CGetByte(I2C_BUS);
return TRUE;
}
else
{
return FALSE;
}
StopTransfer();
return i2cbyte;
}
which always returns FALSE, so it's not even executing the code inside the "if" statement. In other words, the I2CReceivedDataIsAvailable(I2C_BUS) function is returning FALSE, so I'm assuming that means the I2C read buffer is empty.
I searched the web several times to find some info about this and it seems I should be sending the slave adress before reading but, anyway, the buffer is empty so it's not even getting to that part of the code.
Here's the library I wrote for handling the Ds2482:
Code:
#define dly 1000
int Ack_count=1;
char msg[16];
UINT8 mico;
void OW_S(void)
{
StartTransfer(0);
print_error("S");
DelayMs(dly);
}
void OW_Sr(void)
{
//StopTransfer();
StartTransfer(1);
print_error("Sr");
DelayMs(dly);
}
void OW_AD0(UINT8 address)
{
I2C_7_BIT_ADDRESS SlaveAddress;
I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, address, I2C_WRITE);
TransmitOneByte(SlaveAddress.byte);
print_error("AD,0");
DelayMs(dly);
}
void OW_AD1(UINT8 address)
{
I2C_7_BIT_ADDRESS SlaveAddress;
I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, address, I2C_READ);
TransmitOneByte(SlaveAddress.byte);
print_error("AD,1");
DelayMs(dly);
}
void OW_A()
{
if(!I2CByteWasAcknowledged(I2C_BUS)) //OJO CON ESO
{ //EN VOLA WHILE
print_error("NAck");
DelayMs(1*dly);
}
else
{
sprintf(msg,"Ack %d",Ack_count);
print_error(msg);
DelayMs(dly);
Ack_count++;
}
}
void OW_DRST()
{
I2CSendByte(I2C_BUS, 0xF0);
print_error("DRST");
DelayMs(dly);
}
void OW_WCFG(void)
{
I2CSendByte(I2C_BUS, 0xD2);
print_error("WCFG");
DelayMs(dly);
}
void OW_P()
{
StopTransfer();
print_error("P");
DelayMs(dly);
}
void config_status(void)
{
OW_S();
print_status();
OW_AD0(OW_ADDRESS);
print_status();
OW_A(); //Ack1
print_status();
OW_WCFG();
print_status();
OW_A(); //Ack2
print_status();
TransmitOneByte(0xE1);
print_status();
OW_A(); //Ack3
print_status();
OW_Sr();
print_status();
OW_AD1(OW_ADDRESS);
print_status();
OW_A(); //Ack4
print_status();
//DATA
print_status();
OW_A(); //Ack5
print_status();
OW_P();
print_status();
mico=i2c_read_buffer();
print_status();
}
I I made another library with the primitive functions, but I didn't find it useful to post, unless someone asks for it. I'm using another 2 custom libraries for the DelayMs() function and for a 16x2 serial LCD (print_error() function).
Any help would be very appreciated.