Mercurial > public > ostc4
comparison Small_CPU/Src/uart.c @ 809:9602a7338f28
DevBugfix CO2 sensor in streaming mode:
In standalone mode (no multiplexer) the CO2 sensor is working in streaming mode => it could happen that the OSTC received data before the scaling factor was requested. As result the CO2 values were calculated with a zero value. This problem has been fixed.
In addition some code cleanup has been done. Unifying usage of changeBaudrate function instead of old baud selection based on protocol request of Discovery firmware.
author | Ideenmodellierer |
---|---|
date | Sun, 27 Aug 2023 20:51:13 +0200 |
parents | 96ffad0a4e57 |
children | c3dd461ca3f9 |
comparison
equal
deleted
inserted
replaced
808:ea3267866120 | 809:9602a7338f28 |
---|---|
200 } | 200 } |
201 } | 201 } |
202 | 202 |
203 void UART_ChangeBaudrate(uint32_t newBaudrate) | 203 void UART_ChangeBaudrate(uint32_t newBaudrate) |
204 { | 204 { |
205 | 205 uint8_t dmaWasActive = dmaActive; |
206 // HAL_DMA_Abort(&hdma_usart1_rx); | 206 // HAL_DMA_Abort(&hdma_usart1_rx); |
207 MX_USART1_UART_DeInit(); | 207 MX_USART1_UART_DeInit(); |
208 //HAL_UART_Abort(&huart1); | 208 //HAL_UART_Abort(&huart1); |
209 //HAL_DMA_DeInit(&hdma_usart1_rx); | 209 //HAL_DMA_DeInit(&hdma_usart1_rx); |
210 | 210 |
211 | 211 |
212 // huart1.Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq()/2, newBaudrate); | 212 // huart1.Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq()/2, newBaudrate); |
213 huart1.Init.BaudRate = newBaudrate; | 213 huart1.Init.BaudRate = newBaudrate; |
214 HAL_UART_Init(&huart1); | 214 HAL_UART_Init(&huart1); |
215 MX_USART1_DMA_Init(); | 215 MX_USART1_DMA_Init(); |
216 if(dmaActive) | 216 if(dmaWasActive) |
217 { | 217 { |
218 memset(rxBuffer,BUFFER_NODATA,sizeof(rxBuffer)); | |
218 rxReadIndex = 0; | 219 rxReadIndex = 0; |
219 rxWriteIndex = 0; | 220 rxWriteIndex = 0; |
220 dmaActive = 0; | 221 dmaActive = 0; |
221 UART_StartDMA_Receiption(); | 222 UART_StartDMA_Receiption(); |
222 } | 223 } |
390 { | 391 { |
391 rxWriteIndex = 0; | 392 rxWriteIndex = 0; |
392 } | 393 } |
393 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE) || (rxWriteIndex == rxReadIndex)) /* start next transfer if we did not catch up with read index */ | 394 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE) || (rxWriteIndex == rxReadIndex)) /* start next transfer if we did not catch up with read index */ |
394 { | 395 { |
395 if(externalInterface_GetUARTProtocol() != 0) | 396 UART_StartDMA_Receiption(); |
396 { | |
397 UART_StartDMA_Receiption(); | |
398 } | |
399 } | 397 } |
400 } | 398 } |
401 } | 399 } |
402 | 400 |
403 void UART_ReadData(uint8_t sensorType) | 401 void UART_ReadData(uint8_t sensorType) |
439 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | 437 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
440 { | 438 { |
441 rxReadIndex = 0; | 439 rxReadIndex = 0; |
442 } | 440 } |
443 } | 441 } |
444 | 442 } |
445 } | 443 |
444 | |
446 | 445 |
447 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | 446 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |