Hi Guys,
Ok, So I'm back on this now, UART text sorted, but got caught out not saving code history. So by the time I tried the analyser I had modified the code in MPLABX without actually downloading it to the PIC.
I get my stuff delivered to my works address, and having received the analyser rushed home to play with it. Plugged straight into the 'old' version of the program already in the PIC and much to my amazement, it had something going on.
Anyway I'm back to the drawing board. I do know that I took the example code from the I2C.h generated file which gives an example of reading an EEPROM . I removed irrelevant stuff from the example such as the write buffer (as the sensor I am trying to communicate with only requires an single byte address), kept all the timeout & retry loops added some generic delays, but struggling a little with the code. Although it compiles, I have nothing from the analyser, except the UART pin which is working as normal.
None of the debug print statements are executed so it doesn't appear to be entering the I2C wrapper function.
Would appreciate any words of wisdom or suchlike if they're offered...
Here's the code & errors...
- Code: Select all
/**
Section: Included Files
*/
#include "mcc_generated_files/system.h"
#include <libpic30.h> //Defines __delay32();
#include <stdio.h> // Defines printf("");
#include <stdint.h>
#include "mcc_generated_files/uart1.h"
#include "mcc_generated_files/i2c1.h"
const uint16_t BNO_I2C_DEV_ADDR1 = 0x28; // define BNO device default address
const uint8_t BNO_TEMPREG_ADDR = 0x34; // define Temperature register to read from
const uint8_t BNO_RETRY_MAX = 100; // define the retry count
const uint8_t BNO_DEVICE_TIMEOUT = 50 ; // define slave timeout
uint16_t *pDev_Address = &BNO_I2C_DEV_ADDR1;
uint8_t *pReg_Address = &BNO_TEMPREG_ADDR;
uint8_t DataRCVD;
uint8_t *pDataRCVD;
uint8_t status;
uint8_t nBytes = 1;
// MEANINGS OF STATUS INDEX NUMBERS IN THE PRINT STATEMENTS
// 0 - I2C1_MESSAGE_FAIL,
// 1 = I2C1_MESSAGE_PENDING,
// 2 - I2C1_MESSAGE_COMPLETE,
// 3 - I2C1_STUCK_START,
// 4 - I2C1_MESSAGE_ADDRESS_NO_ACK,
// 5 - I2C1_DATA_NO_ACK,
// 6 - I2C1_LOST_STATE
// Start Wrapper Function
uint8_t BNO055_Read_Temp(uint16_t pDev_Address, uint8_t nBytes, uint8_t pReg_Address,uint8_t pDataRCVD)
{
I2C1_MESSAGE_STATUS status;
uint16_t retryTimeOut, slaveTimeOut;
printf("Read Function initiated..\r\n"); // Print prog status to terminal for debug;
retryTimeOut = 0; //Initialise timeout & retry variables to zero
slaveTimeOut = 0;
while(status != I2C1_MESSAGE_FAIL)
{
I2C1_MasterWrite(pReg_Address,nBytes,pDev_Address,&status); // start write
printf("Write initiated..\r\n"); // Print prog status to terminal for debug;
while(status == I2C1_MESSAGE_PENDING)
{
__delay32(50000);
if (slaveTimeOut == BNO_DEVICE_TIMEOUT)
return (0);
else
slaveTimeOut++; // slave timeout inc
}
if (retryTimeOut == BNO_RETRY_MAX)
break;
else
retryTimeOut++; // retry timeout inc
if (status == I2C1_MESSAGE_COMPLETE)
break;
} // status write complete
if (status == I2C1_MESSAGE_COMPLETE)
{
retryTimeOut = 0; // reset counters
slaveTimeOut = 0;
}
while(status != I2C1_MESSAGE_FAIL)
{
I2C1_MasterRead(pDataRCVD,nBytes,pDev_Address,&status); // start read
while(status == I2C1_MESSAGE_PENDING)
{
__delay32(50000);
if (slaveTimeOut == BNO_DEVICE_TIMEOUT)
return (0);
else
slaveTimeOut++; // slave timeout inc
if (status == I2C1_MESSAGE_COMPLETE)
break;
if (retryTimeOut == BNO_RETRY_MAX)
break;
else
retryTimeOut++; // retry timeout inc
}
if (status == I2C1_MESSAGE_FAIL)
{
return(0);
break; // read fail
}
return(1);
}
return(status);
}
/*
Main application
*/
int main(void)
{
// initialise the device
SYSTEM_Initialize();
// ALSO INITIALISED IN SYSTEM.C ARE
// PIN_MANAGER_Initialise();
// CLOCK_Initialise();
// INTERRUPT_Initialise();
// UART1_Initialise();
// I2C1_Initialise();
// **************************************
printf("Explorer 16/32, ICD3, PIC24FJ256GB110 PIM\n\r");
printf("MPLABX, MMC, XC16\n\r");
printf("BNO055 temperature out to terminal test - 01-12-19 \n\n\r");
while (1)
{
// Call Wrapper Function
uint8_t BNO055_Read_Temp(uint16_t pDev_Address, uint8_t nBytes, uint8_t pReg_Address,uint8_t pDataRCVD);
__delay32(50000);
DataRCVD = *pDataRCVD;
printf("BNO055 Temp is %u , Status is: %u\r", DataRCVD,status);
__delay32(50000);
}
}
/**
End of File
*/
main.c:61:30: warning: initialization discards qualifiers from pointer target type
main.c:62:29: warning: initialization discards qualifiers from pointer target type
main.c: In function 'BNO055_Read_Temp':
main.c:87:25: warning: passing argument 1 of 'I2C1_MasterWrite' makes pointer from integer without a cast
mcc_generated_files/i2c1.h:274:6: note: expected 'uint8_t *' but argument is of type 'uint8_t'
main.c:112:41: warning: passing argument 1 of 'I2C1_MasterRead' makes pointer from integer without a cast
mcc_generated_files/i2c1.h:447:6: note: expected 'uint8_t *' but argument is of type 'uint8_t'
Regards
Les
History teaches us that history doesn't teach us.