cancel
Showing results for 
Search instead for 
Did you mean: 

How to use I2C to read GPIO pins on STM3241G-Eval

valtteri
Associate II

Hi,

I have STM3241G-Eval board and I'm trying to learn things.

Did some LED blinking and now trying to get in to the I2C world.

So I created a project with STM32CubeMX and initialized all peripherals with their default Modes.

I enabled FREERTOS and generated the code. Using FREERTOS because I might need it in the future.

I'd like to read the state of eval board's joystick with i2c. CubeMX connects I2C1 to B6 and B9.

STMPE811 where the joystick is connected is at address 0x88.

STMPE811 port expander has address 0x12 for monitoring GPIO pin state.

0690X0000088KIcQAM.jpg

0690X0000088KKxQAM.jpg

0690X0000088KLWQA2.jpg

0690X0000088KMFQA2.jpg

Now I'm trying to understand how to use HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive.

I have created buffer for data to send and receive. How big shoud it be?

unsigned char buffer1[1];

unsigned int b1 = 0;

unsigned int b2 = 0;

I have function where I set the address to 0x88 and shift to left as the HAL library says.

When transmitting I just send one byte with address 0x12.

After this I try to receive in a loop. There is no delay in the loop, should there be?

void JoyStatus(void *pvParameters)

{

 buffer1[0] = 0x12;

 HAL_I2C_Master_Transmit(&hi2c1, 0x88<<1, buffer1,1, 100);

buffer1[0] = 0;

for(;;)

{

HAL_I2C_Master_Receive(&hi2c1, 0x88<<1, buffer1,1, 100);

b1 = buffer1[0];

b2 = buffer1[1];

}

}

xTaskCreate(JoyStatus,(const char* const)"joy_status", configMINIMAL_STACK_SIZE,0,2,0);

When I debug this the content of buffer stays zero. First time using I2C so there is probably something that I don't understand here.

Any comments? Thanks.

0 REPLIES 0