Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

How to use CAN?

Posted by Nobody/Anonymous on October 20, 2005
Hi,

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:

{
char cDestination;
char *pcData;
int iDataLength;
}

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.

Regards.



[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner