Hi peeps,
I've just picked this up again after 6 months or so as I need to put a new PC together.
I've had it working a few times but not giving the expected logic output.
I've tried to comment it up somewhat to explain what I think it's doing or should be doing.
I'm attempting to write as a block of data two bytes, namely the (operation mode) register address & the register value.
If you guys could flame me with some blatently stupid errors I'd appreciate it.
Any help would be appreciated.
Regards
GB
I've just picked this up again after 6 months or so as I need to put a new PC together.
I've had it working a few times but not giving the expected logic output.
I've tried to comment it up somewhat to explain what I think it's doing or should be doing.
I'm attempting to write as a block of data two bytes, namely the (operation mode) register address & the register value.
If you guys could flame me with some blatently stupid errors I'd appreciate it.
main.c:
/**
@File Name
main.c
*/
/**
PROJECT NAME: X1632-8Mhz_BNO055_Comms3
Section: Included Files
*/
#include "xc.h"
#include "mcc_generated_files/system.h"
#include "mcc_generated_files/uart1.h"
#include "mcc_generated_files/i2c1.h"
#include <libpic30.h> //Defines __delay32();
#include <stdio.h> // Defines printf("");
int main(void)
{
// initialise the device
SYSTEM_Initialize();
/* INITIALISES THE FOLLOWING
PIN_MANAGER_Initialize();
CLOCK_Initialize();
INTERRUPT_Initialize();
I2C1_Initialize();
UART1_Initialize();
INTERRUPT_GlobalEnable();
SYSTEM_CORCONModeOperatingSet(CORCON_MODE_PORVALUES);
*/
__delay32(5000);
// SYSTEMS USED & PROJECT AIMS
printf("Explorer 16/32 v3 DM240001-3, ICD4, dsPIC33CH128MP508 PIM\n\r");
printf("MPLABX v5.4, MCC v4.0.2, XC16 v1.60\n\r");
printf("Project Name: X1632-8Mhz_BNO055_Comms3\n\r");
printf("Simple write to BNO055 Comms via I2C\n\n\r");
// This ^^ all works fine.
/*
* From To Switching time
* CONFIGMODE Any operation mode 7ms
* Any operation mode CONFIGMODE 19ms
*/
#define CONFIGMODE (00000000) // default value = config mode
#define OPR_MODE (00111101) //Register 0x3D
#define ACCGYRO_CON (00000101) //Register Value 0x05
#define BNO55_I2C_ADDR (00101000) //Slave Device Address 0x28
// In debug mode in MPLABX, when hovering the above shows as "Not recognised"
uint8_t counter;
uint8_t *pdata; // block to be sent, in this case the address of the register to write to, and the value to write.
uint8_t length; // number of elements in pdata.
uint16_t address; // Slave device address.
I2C1_MESSAGE_STATUS *pstatus; //I2C returned status message.
length = 2; // number of bytes to transfer in the for loop.
address = (BNO55_I2C_ADDR>>8); // Shift the value to the LSB as only writing 7 bit address.
while(pstatus != I2C1_MESSAGE_FAIL) // After I2C1_MasterWrite is called this status is returned. The default is ENUMERATING and so satisfys the test.
{
for (counter =0; counter < length ;counter++) //counter to loop increment 'operation mode' Register & value index.
{
// SET OP_MODE TO ACCGYRO
uint8_t data[2] = {OPR_MODE, ACCGYRO_CON}; //address of the OP_MODE register to write to, and the value to write.
pdata = &data[counter]; // transfer first byte of data.
I2C1_MasterWrite(*pdata, length, address, pstatus);
__delay32(5000);
printf("I2C Message status = %08x \n\r",pdata); //debug
__delay32(5000);
}
}
printf("I2C Message status = %c \n\r",pstatus); //debug
printf("Device Address = %08x \n\r",address); //debug
}
/**
End of File
*/
Regards
GB