How to use CAN?
Posted by Nobody/Anonymous on October 20, 2005
thanks a lot for your great FreeRTOS project. I'm working on a controller project that uses CAN. Are you aware of any applications that have used CAN within FreeRTOS tasks?
I would also like to interface SPI peripherals, but the two peripherals I plan to use would be used by differnt tasks (one is a sensor with an integrated AD converter, the other an SPI based flash for logging). How could this be done?
RE: How to use CAN?
Posted by Richard
on October 20, 2005
>I'm working on a controller project that uses CAN
I think this is something that has been discussed here before, or maybe it was on the LPC2000 forum? Unfortunately CAN is not easy to use as a search term as nearly every post is returned.
Using CAN should be straight forward. The preferred method of processing peripherals is to have a very short interrupt routine that reads the data from the peripheral, clears the interrupt, then sends the data to a task for processing at the task level. How the data is sent to the task is dependent on your project requirements. You can use a queue or a simple circular buffer. The queue has a slightly higher time overhead, but allows the task waiting to receive the data to be woken as soon as data is received, and if necessary run immediately that the ISR has completed (if its priority is higher than the interrupted task). A simple circular buffer efficient, but you don't get the automatic task notification. You can use the UART driver sample to see the necessary syntax for your particular part and compiler.
>I would also like to interface SPI peripherals, but the
>two peripherals I plan to use would be used by
>differnt tasks (one is a sensor with an integrated AD
>converter, the other an SPI based flash for logging).
>How could this be done?
All you have to watch out for is that both tasks don't attempt to use the SPI at the same time. One way of doing this is to not access the peripheral directly but instead use queues, as per the UART example. The SPI send function can just write the data to a queue. The SPI driver then reads the data from the queue. The driver then guarantees sequential access with one message being processed at a time. You can queue a pointer to a structure of the form:
When the driver obtains this from the queue, it then knows which peripheral to send the data to, where to obtain the data to be transmitted, and how much data to send.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.