I have a task where spi_write_read_blocking
returns 95 for the first few task iterations then returns 1023 forever. The code works when not using it in a FreeRTOS task.
xTaskCreate(windDirectionTask, "WindDirectionTask", 1024, NULL, TASK_PRIORITY, &windDirectionTaskHandle);
the data
variable below starts at 95 for the first few iterations then changes to 1023 forever:
void windDirectionTask(__unused void* pvParameters) {
int chan = 0;
uint8_t buffer[3];
buffer[0] = 1;
buffer[1] = (8 + chan) << 4;
buffer[2] = 0;
while(true) {
cs_select();
sleep_ms(10);
uint8_t returnData[10];
spi_write_read_blocking(SPI_PORT, buffer, returnData, sizeof(buffer));
int data = ( (returnData[1]&3) << 8 ) | returnData[2];
cs_deselect();
sleep_ms(10);
getDirectionFromADCValue(data, windDirectionName);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
Is there a standard way to use spi from a task? The task reads an ADC which reads the voltage from a wind vane.