Skip to content

Commit d011bbd

Browse files
authored
START/SYNC Function & Async RX functions
1 parent d5ca73c commit d011bbd

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

ADS1220/ads1220.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,63 @@
55
* Author: Felipe Navarro
66
*
77
*/
8+
#include "ads1220.h"
9+
10+
/*
11+
* Function to Start a new conversion on Single Shot Mode of ADS1220
12+
*/
13+
int8_t ADS1220_start_conversion(SemaphoreHandle_t * Mutex_SPI){
14+
15+
//Take SPI Semaphore before using the SPI
16+
if( xSemaphoreTake( Mutex_SPI, (TickType_t) 5) == pdTRUE ){
17+
HAL_GPIO_WritePin(CS_ADS1220_GPIO_Port , CS_ADS1220_Pin, GPIO_PIN_RESET); // Lower CS before writing to SPI
18+
19+
//Try to TX the START/SYNC command
20+
if(HAL_SPI_Transmit(&hspi1, (uint8_t) ADS1220_START_SYNC, 1, 10) != HAL_OK ){
21+
22+
//If we doesn't get a HAL_OK - Free Mutex, SET CS_ADS1220 and return SPI_FAULT
23+
HAL_GPIO_WritePin(CS_MAX31865_GPIO_Port, CS_MAX31865_Pin, GPIO_PIN_SET);
24+
xSemaphoreGive(Mutex_SPI);
25+
return ADS1220_SPI_FAULT;
26+
}
27+
//In case of Success
28+
HAL_GPIO_WritePin(CS_ADS1220_GPIO_Port, CS_ADS1220_Pin, GPIO_PIN_SET);
29+
xSemaphoreGive(Mutex_SPI);
30+
return ADS1220_SUCCESS;
31+
}
32+
else
33+
{
34+
//If couldn't acquire the Semaphore, signal Semaphore Fault
35+
return ADS1220_SEMAPHORE_FAULT;
36+
}
37+
}
38+
39+
/*
40+
* Function to config the ADS1220 with hard-coded parameters
41+
*/
42+
int8_t ADS1220_config(SemaphoreHandle_t * Mutex_SPI){
43+
44+
}
45+
46+
/*
47+
* t_RX_ADS1220
48+
*
49+
* Task to RX the ADS1220 data
50+
* This task receives a Task Notification to get out of SUSPENDED mode
51+
* and do the RX of the ADS1220 data.
52+
*
53+
* You need to pass the SPI Semaphore Handle thru the pvParameters when
54+
* you create the task
55+
*
56+
*/
57+
void t_RX_ADS1220(void * pvParameters){
58+
59+
SemaphoreHandle_t Mutex_SPI = (SemaphoreHandle_t) pvParameters;
60+
61+
for(;;){
62+
//Wait forever until we receive a signal that the ADS1220 has some data to be received
63+
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
64+
65+
66+
}
67+
}

ADS1220/ads1220.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,7 @@ enum ADS1220_FAULTS{
178178
}ADS1220_FAULTS;
179179

180180
// Functions and Tasks Prototypes
181-
181+
int8_t ADS1220_start_conversion(SemaphoreHandle_t * Mutex_SPI);
182+
int8_t ADS1220_config(SemaphoreHandle_t * Mutex_SPI);
183+
void t_RX_ADS1220(void * pvParameters);
182184

0 commit comments

Comments
 (0)