Author Topic: I2C / TWI for Arduino with FreeRTOS?  (Read 3098 times)

0 Members and 1 Guest are viewing this topic.

Offline zaphod_bTopic starter

  • Newbie
  • Posts: 3
  • Country: de
I2C / TWI for Arduino with FreeRTOS?
« on: February 02, 2018, 05:11:48 pm »
Hi,
anybody out there with a good 'hello world' for making I2C work on an Arduino Mega under FreeRTOS?
Seems there is not so much stuff out there on Google (spent nearly 2 days) covering the Arduino / AVR / Atmel platform.
Yeah - SPI seems to be working - but not much on I2C.
I am currently building a smallish project requiring reading / writing to sensors and a display using TWI / I2C and all efforts I made ended nowhere.
I surely can talk to my I2C bus devices - but when I start the scheduler vTaskStartScheduler() everything stops working.
I tried the usual suspects (turning off interrupts / Semaphores / taskENTER_CRITICAL() ) - without success.
Don't want to spend too much time rewriting existing libraries etc.
So: Do you have any template / library files that make i2c easy for FreeRTOS on Arduino?
 

Online iMo

  • Super Contributor
  • ***
  • Posts: 4790
  • Country: pm
  • It's important to try new things..
Re: I2C / TWI for Arduino with FreeRTOS?
« Reply #1 on: February 02, 2018, 07:25:46 pm »
You have to create a mutex and guard the call to the I2C resource with

xSemaphoreTake
.. here the I2C access
xSemaphoreGive

See for example: https://www.freertos.org/a00122.html
 
The following users thanked this post: zaphod_b

Offline rheb1026

  • Regular Contributor
  • *
  • Posts: 101
  • Country: us
Re: I2C / TWI for Arduino with FreeRTOS?
« Reply #2 on: February 03, 2018, 05:04:30 am »
You can try adding more to that I2C tasks stack size. I’ve found this is usually the cause of my programs locking up when I make changes.

I’d suggest enabling the task overflow hook during development/debug. Makes it really easy to find the offending task
 
The following users thanked this post: zaphod_b

Offline zaphod_bTopic starter

  • Newbie
  • Posts: 3
  • Country: de
Re: I2C / TWI for Arduino with FreeRTOS?
« Reply #3 on: February 06, 2018, 01:38:46 pm »
@IMO: As there is only one task in my demo code that uses the I2C bus I believe that this will not make a difference as there are no other competing tasks for this resource. (and I tried it before as well but without success)...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf