comparison Small_CPU/Src/uart.c @ 725:621265ec3d23

Update CO2 sensor implementation: Some updates were needed to get the CO2 sensor code up and running again (menu handling and UART DMA transfer).
author Ideenmodellierer
date Sat, 07 Jan 2023 18:11:52 +0100
parents fceae45b3a69
children d646a0f724a7
comparison
equal deleted inserted replaced
724:f285424f04d9 725:621265ec3d23
146 uint8_t dataType = 0; 146 uint8_t dataType = 0;
147 uint32_t dataValue = 0; 147 uint32_t dataValue = 0;
148 static receiveState_t rxState = RX_Ready; 148 static receiveState_t rxState = RX_Ready;
149 static uint32_t lastReceiveTick = 0; 149 static uint32_t lastReceiveTick = 0;
150 150
151 while(localRX != rxWriteIndex) 151
152 while((rxBuffer[localRX]!=0))
152 { 153 {
153 lastReceiveTick = HAL_GetTick(); 154 lastReceiveTick = HAL_GetTick();
154 if(rxState == RX_Ready) /* identify data content */ 155 if(rxState == RX_Ready) /* identify data content */
155 { 156 {
156 switch(rxBuffer[localRX]) 157 switch(rxBuffer[localRX])
165 166
166 default: /* unknown or corrupted => ignore */ 167 default: /* unknown or corrupted => ignore */
167 break; 168 break;
168 } 169 }
169 } 170 }
170 else if((rxState >= RX_Data0) && (rxState <= RX_Data4)) 171 else if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9'))
171 { 172 {
172 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) 173 if((rxState >= RX_Data0) && (rxState <= RX_Data4))
173 { 174 {
174 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0'); 175 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0');
175 rxState++; 176 rxState++;
177 if(rxState == RX_Data5)
178 {
179 rxState = RX_DataComplete;
180 }
181 }
182 else /* protocol error data has max 5 digits */
183 {
184 rxState = RX_Ready;
176 } 185 }
177 } 186 }
178 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */ 187 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */
179 { 188 {
180 if(rxState == RX_DataComplete) 189 if(rxState == RX_DataComplete)