Problem with XMC4400 and MAX44009 sensor light (I2C)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hello everyone!

I'm having troubles trying to connect my light sensor (MAX44009) with I2C. I will explain what i've done and i hope someone can help me.

2569.attach

I am connecting this card on HMI port of my XMC4400.

2568.attach

I've connected the sensor according to this table.
SCA - pin37
SCL - pin38
GND - pin 80
3.3 - pin 3.3V of XMC4400

Then i've tried to adapt the I2C Master example (available on DAVE tutorials) for my light sensor. I've created an I2C master app with the following settings:

2570.attach

2571.attach

My main.c is this:



#include




#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);
}

/*
* For this demo the HMI satellite board for the XMC45 CPU board is required.
* It communicates with the IO expander (U360: PCA9502) found in the mentioned satellite board.
* The demo implements a binary counter using the LEDs attached to the IO expander.
*
*/
int main(void)
{

DAVE_Init();

uint8_t received_data;
uint8_t counter = 0;

/* Write data to reset the LEDs through the IO EXPANDER: DIR and 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 to set the STATE of the 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 the data from the 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 the received data is correct*/
if(tx_buffer[3] != received_data)
{
// while(1);
}
/* Delay to make visible the change */
delay(0xfffff);
}
while(1);
return 0;
}


I think my callback functions are not working, since it stops every time i execute one I2C function. on this case is on line 108. Plus, sometimes it gives me an error/warning : No source available on 0x00.
2572.attach

I have a python code that works fine on my sensor light when i'm using raspberry pi, i've tried to do the same thing on XMC but withou success. I hope you can help me.

Thanks in advice,
Ricardo
0 Likes
3 Replies
User12775
Level 5
Level 5
First solution authored First like received
Observe the signal waveform of both the PI and your XMC4 board using a oscilloscope.
Compare them or post the captures here.
0 Likes
Not applicable
aurixuser wrote:
Observe the signal waveform of both the PI and your XMC4 board using a oscilloscope.
Compare them or post the captures here.


Hey! Thanks for the tip. Actually the two Signals are different, but i dont know why..


XMC:2579.attach




python:2578.attach



thanks for the help
0 Likes
User12775
Level 5
Level 5
First solution authored First like received
Channel 1 is SCK.
Channel 2 is SDA.

Right?

The first difference is the number of pulse on the SCK line.
The Python one seems send 3 bytes of clock.
The XMC one possibly misses one byte.
0 Likes