-
Notifications
You must be signed in to change notification settings - Fork 1
Home
foxhounddm edited this page Jan 24, 2021
·
8 revisions
You may use your own project or generate project using STMCubeMX Minimum requirements is
- initialize UART is asynchronous mode
- configure DMA for RX and TX for that UART
- enable half buffer transfer interrupts for DMA (RX and TX)
- enable general interrrupts for UART
- call OneWire methods form interupts
void DMA1_Channel6_IRQHandler(void) {
oneWirePtr->receiveHalfBuffer();
HAL_DMA_IRQHandler(&hdma_usart2_rx);
}
void DMA1_Channel7_IRQHandler(void) {
oneWirePtr->sendHalfBuffer();
HAL_DMA_IRQHandler(&hdma_usart2_tx);
}
void USART2_IRQHandler(void) {
if (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_TC)) {
oneWirePtr->uartFinish();
}
HAL_UART_IRQHandler(&huart2);
}
OneWire oneWire = OneWire(&huart2);
oneWirePtr = &oneWire;
DallasTemperature ds = DallasTemperature(&oneWire);
uint8_t deviceCount = oneWire.getDeviceCount();
ds.setResolution(9);
ds.requestTemperatures();
HAL_Delay(1000);
for(uint8_t i=0; i<deviceCount; i++ ) {
uint64_t addr = oneWire.getDeviceAddress(i);
if( ds.isTemperatureSensor(&addr)){
float temperature = ds.getTempC(&addr);
}
}