I2C Master/Multi-Master/Slave with FreeRTOS

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

cross mob
ZvVe_2582751
Level 1
Level 1
5 replies posted Welcome! 5 questions asked

Hello,

I developed an application that uses the following calls of:

uint8 I2C_MasterWriteBuf(uint8 slaveAddr, uint8 * wrData, uint8 cnt, uint8 mode)

uint8 I2C_MasterReadBuf(uint8 slaveAddr, uint8 * rdData, uint8 cnt, uint8 mode)

In order to read data from FRAM.

It works fine.

Then I integrated FreeRTOS inside  this application.

The IIC is a resource that should be used in few tasks.

So I create a counting semaphore in order to implement a critical section:

xSemaphoreTake (..)

I2C_MasterWriteBuf (..)

xSemaphoreGive (..)

The problem:

I created the semaphore with:

SemaphoreHandle_t  sem = xSemaphoreCreateCounting(1, 1);

After the semaphore creation, I2C_MasterWriteBuf started to return 2 and not 0.

I did not call to xSemaphoreTake and xSemaphoreGive  yet.

What can cause it ?

Thank you,

Zvika

0 Likes
6 Replies
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi Zvi,

Which device and IDE are you using?

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes

Hi Trung,

Can you refer to the code example CE223468 – PSoC 6 MCU: Interfacing BMI160 (I2C) in FreeRTOS?

http://www.cypress.com/documentation/code-examples/ce223468-psoc-6-mcu-interfacing-bmi160-i2c-freert...

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes

Hi Bragadeesh,

I'm using Creator 4.0, PSOC 5 (CY8C5868AXI-LP035)

Thank you,

Zvika

0 Likes

Hi Zvika,

Can you please check if any other task is using the I2C bus line? Because the MasterWriteBuf returning 2 means "the master is not a valid master on the bus, or a slave operation is in progress". I'm suspecting that some other task has not given up the I2C resource?  Was the previous code example I shared of any use?

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes

Hi Bragadeesh,

Thank you for your help !

I got rc=2 before any task was launched and before calling to xSemaphoreTake.

In the init phase of the application I called xSemaphoreCreateCounting.

If the semaphore is not created, rc=0.

No one is using the semaphore at this stage.

Best regards,

Zvika

0 Likes

Hi,

Can you please share your project file here so that I will try to find out the issue?

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes