Hi,
I am able to port freeRTOS onto the MSP430F5529 LP using code composer studio.
The source code provided below is an example I’m following.
I modified the example to try and add I2C functionality. The I2C code works well in a while(1) loop, but when I add an “i2c_readword()” to try and read 2 bytes from the same register in the RTOS Task 1 function, I start getting issues on the USCI_B0 peripheral. It looks like the I2C bus is getting out of sync when I put a Saleae logic analyzer on the transaction. I even removed one task and just went to a single task, but it still doesn’t work.
I tried to add a mutex block, not successful, still looks out of sync.
What could be going wrong? Is it my implementation?
My I2C driver does not use any low power modes, but I do trigger interrupts and when I’m waiting for the interrupts, I’m polling for a complete flag.
Sample Code Below.
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "queue.h"
static void prvSetupHardware( void )
{
taskDISABLE_INTERRUPTS();
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//P1.0,LED1 for indicating sensors are gathering data
P1DIR |= BIT0;
P4DIR |= BIT7;//P4.7,LED2 for sending data to PC
}
void vBlink1(void * pvParameters)
{
const TickType_t xDelay = 100 / portTICK_PERIOD_MS;
for(;;)
{
P1OUT^=BIT0;
//P4OUT^=BIT7;
vTaskDelay( xDelay );
}
}
void vBlink2(void * pvParameters)
{
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
for(;;)
{
P4OUT^=BIT7;
//Tried to add I2C below
//I2C_ReadWord();
vTaskDelay( xDelay );
}
}
int main( void )
{
/* Perform any hardware setup necessary. */
prvSetupHardware();
/* --- APPLICATION TASKS CAN BE CREATED HERE --- */
/* Start the created tasks running. */
xTaskCreate( vBlink1, "Blink1",
configMINIMAL_STACK_SIZE, NULL, 1, NULL );
xTaskCreate( vBlink2, "Blink2",
configMINIMAL_STACK_SIZE, NULL, 1, NULL );
vTaskStartScheduler();
/* Execution will only reach here if there was
insufficient heap to start the scheduler. */
for( ;; );
return 0;
}
/*-----------------------------------------------------------*/
/* The MSP430X port uses this callback function to configure its tick interrupt.This allows the application to choose the tick interrupt source. configTICK_VECTOR must also be set in FreeRTOSConfig.h to the correct interrupt vector for the chosen tick interrupt source. This implementation of vApplicationSetupTimerInterrupt() generates the tick from timer A0, so in this case configTICK_VECTOR is set to TIMER0_A0_VECTOR. */
void vApplicationSetupTimerInterrupt( void )
{
const unsigned short usACLK_Frequency_Hz = 32768;
/* Ensure the timer is stopped. */
TA0CTL = 0;
/* Run the timer from the ACLK. */
TA0CTL = TASSEL_1;
/* Clear everything to start with. */
TA0CTL |= TACLR;
/* Set the compare match value according to
the tick rate we want. */
TA0CCR0 = usACLK_Frequency_Hz / configTICK_RATE_HZ;
/* Enable the interrupts. */
TA0CCTL0 = CCIE;
/* Start up clean. */
TA0CTL |= TACLR;
/* Up mode. */
TA0CTL |= MC_1;
}
/*-----------------------------------------------------------*/