c - XMC4400 and MAX44009 sensor light (I2C) -


i'm having trouble trying connect light sensor (max44009) i2c. explain i've done , hope can me.

i connecting connection card on hmi port of xmc4400 80 ports.

enter image description here

i've connected sensor according table. sca - pin37 scl - pin38 gnd - pin 80 3.3 - pin 3.3v of xmc4400

then i've tried adapt i2c master example (available on dave tutorials) light sensor. i've created i2c master app following settings:

enter image description here

enter image description here

my main.c this:

code:

#include <dave.h>            #define io_expander_address  (0x4a)   uint8_t tx_buffer[4] = {0x00,0x01,0x02,0x03};   volatile uint8_t tx_completion_0 = 0;  volatile uint8_t rx_completion_0 = 0;   /* transmit callback handling */  void tx_callback_0(void)  {    tx_completion_0 = 1;  }  /* receive callback handling */  void rx_callback_0(void)  {    rx_completion_0 = 1;  }  /* delay */  void delay(uint32_t counter)  {     volatile uint32_t cnt = counter;     while(--cnt);  }   /*   * demo  hmi satellite board xmc45 cpu board required.   * communicates io expander (u360: pca9502) found in mentioned satellite board.   * demo implements binary counter using leds attached io expander.   *   */  int main(void)  {    dave_init();    uint8_t received_data;   uint8_t counter = 0;    /* write data reset leds through io expander: dir , 0xff */   i2c_master_transmit(&i2c_master_0,true,io_expander_address,&tx_buffer[1],2,false);   while(tx_completion_0 == 0);   tx_completion_0 = 0;      while(counter < 255)   {      tx_buffer[3] = ~counter;     counter++;      /* write data set state of io expander */     i2c_master_transmit(&i2c_master_0,true,io_expander_address,&tx_buffer[3],2,false);     while(tx_completion_0 == 0){        tx_callback_0();      }     tx_completion_0 = 0;      /* receive data io expander */     i2c_master_receive(&i2c_master_0,true,io_expander_address,&received_data,2,true,true);     printf("%d", received_data);     while(rx_completion_0 == 0){         rx_callback_0();     }     rx_completion_0 = 0;     /* check if received  data correct*/     if(tx_buffer[3] != received_data)     {      // while(1);     }     /* delay make visible change */     delay(0xfffff);   }   while(1);   return 0;  } 

i think callback functions not working, since stops every time execute 1 i2c function. on case on line 108. plus, gives me error/warning:

no source available on 0x00.

import smbus import time  # i2c bus bus = smbus.smbus(1)  # max44009 address, 0x4a(74) # select configuration register, 0x02(02) #       0x40(64)    continuous mode, integration time = 800 ms bus.write_byte_data(0x4a, 0x02, 0x40)  time.sleep(0.5)  # max44009 address, 0x4a(74) # read data 0x03(03), 2 bytes # luminance msb, luminance lsb data = bus.read_i2c_block_data(0x4a, 0x03, 2)  # convert data lux exponent = (data[0] & 0xf0) >> 4 mantissa = ((data[0] & 0x0f) << 4) | (data[1] & 0x0f) luminance = ((2 ** exponent) * mantissa) * 0.045  # output data screen print "ambient light luminance : %.2f lux" %luminance 

i have python code works fine on sensor light when i'm using raspberry pi, i've tried same thing on xmc without success. hope can me.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -