Doubts about i2c in CCS compiler

1

I have a question about the i2c protocol programming in CCS Compiler with a specific sensor.

To fully synthesize I give you an example that appears in the sensor datasheet to obtain data of it.

And then I present the code in CCS:

 #include <18f2550.h>
 #fuses   HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
 #USE     delay(clock=48000000)
 #use i2c(Master,Fast,sda=PIN_B0,scl=PIN_B1)

 #include <usb_cdc.h>


 void main() {

 i2c_start();
 i2c_write(0x54);
 i2c_write(0x00);
 i2c_write(0x89);
 i2c_write(0x54);
 i2c_write(0x00);
 i2c_write(0x09);
 i2c_stop();

 usb_cdc_init();
 usb_init();

       while(TRUE) {

           delay_ms(10);
           i2c_write(0x54);
           i2c_write(0x03);
           i2c_write(0x55);

           int8 RM=i2c_read(1);
           int8 RL=i2c_read(1);
           unsigned char GM=i2c_read(1);
           unsigned char GL=i2c_read(1);
           unsigned char BM=i2c_read(1);
           unsigned char BL=i2c_read(1);
           unsigned char IM=i2c_read(1);
           unsigned char IL=i2c_read(0);
           i2c_stop();

           usb_task();


               if (usb_enumerated()) {


                     printf( usb_cdc_putc,"%d", (RM << 8) | RL );                        
                     printf(usb_cdc_putc, "\f ");

               }

       }

  }

I would like to know if you find a fault because the data collection seems a little random and I am not sure if I have programmed well as it appears in the datasheet.

I attached the PDF of the sensor in case someone wanted to help and delve more into the programming of this. ---- > Sensor Datasheet Link

    
asked by Alberto 17.12.2018 в 18:04
source

0 answers