Not applicable
Mar 28, 2017
03:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 28, 2017
03:58 AM
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.
I am connecting this card on HMI port of my XMC4400.
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:
My main.c is this:
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.
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
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.
I am connecting this card on HMI port of my XMC4400.
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:
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.
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
3 Replies
Mar 28, 2017
04:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 28, 2017
04:17 AM
Observe the signal waveform of both the PI and your XMC4 board using a oscilloscope.
Compare them or post the captures here.
Compare them or post the captures here.
Not applicable
Mar 29, 2017
08:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 29, 2017
08:35 AM
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:
python:
thanks for the help
Mar 30, 2017
02:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mar 30, 2017
02:55 AM
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.
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.