Implement first working version of DMX receiver. Might still be buggy

This commit is contained in:
Mario Hüttel 2022-07-07 17:40:25 +02:00
parent 60f1923abe
commit 8dc30f15fb
3 changed files with 16 additions and 6 deletions

View File

@ -3,11 +3,15 @@
static uint32_t dmx_base_channel; static uint32_t dmx_base_channel;
enum dmx_rx_state_enum { enum dmx_rx_state_enum {
DMX_RX_WAIT_FOR_BREAK = 0, DMX_RX_WAIT_FOR_BREAK = 0,
DMX_RX_DATA, DMX_RX_DATA,
}; };
static volatile enum dmx_rx_state_enum dmx_state;
static volatile bool break_received; static volatile bool break_received;
/** /**
@ -71,17 +75,22 @@ void USART1_IRQHandler(void)
if (isr & USART_ISR_FE) { if (isr & USART_ISR_FE) {
/* Frame error received. Start of DMX frame */ /* Frame error received. Start of DMX frame */
/* Flush RX data */ /* Flush RX data */
USART1->CR3 &= ~USART_CR3_DMAR;
USART1->RQR = USART_RQR_RXFRQ; USART1->RQR = USART_RQR_RXFRQ;
USART1->CR3 |= USART_CR3_DMAR;
DMA1_Channel3->CCR &= ~DMA_CCR_EN; DMA1_Channel3->CCR &= ~DMA_CCR_EN;
while (DMA1_Channel3->CCR & DMA_CCR_EN);
DMA1_Channel3->CMAR = (uint32_t)dmx_channel_data; DMA1_Channel3->CMAR = (uint32_t)dmx_channel_data;
DMA1_Channel3->CPAR = (uint32_t)&USART1->RDR; DMA1_Channel3->CPAR = (uint32_t)&USART1->RDR;
DMA1_Channel3->CNDTR = DMX_UNIVERSE_SIZE + 1; DMA1_Channel3->CNDTR = DMX_UNIVERSE_SIZE + 1;
DMA1_Channel3->CCR |= DMA_CCR_EN; DMA1_Channel3->CCR |= DMA_CCR_EN;
USART1->RQR = USART_RQR_RXFRQ;
USART1->CR3 |= USART_CR3_DMAR; USART1->CR3 |= USART_CR3_DMAR;
break_received = true; break_received = true;
dmx_state = DMX_RX_DATA;
} else if (isr & USART_ISR_RXNE) { } else if (isr & USART_ISR_RXNE) {
if (dmx_state != DMX_RX_DATA) {
USART1->RQR = USART_RQR_RXFRQ;
}
} }
__DSB(); __DSB();
@ -97,6 +106,7 @@ void DMA_CH2_3_DMA2_CH1_2_IRQHandler(void)
if (isr & DMA_ISR_TCIF3) { if (isr & DMA_ISR_TCIF3) {
DMA1->ISR; DMA1->ISR;
dmx_state = DMX_RX_WAIT_FOR_BREAK;
} }
__DSB(); __DSB();
} }

View File

@ -6,7 +6,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#define DMX_UNIVERSE_SIZE (255u) #define DMX_UNIVERSE_SIZE (512u)
#define DMX_USED_CHANNEL_COUNT (129u) #define DMX_USED_CHANNEL_COUNT (129u)
/** /**

View File

@ -220,9 +220,9 @@ int main(void)
last_led_val = led_val; last_led_val = led_val;
} }
/* Only wait in case of non-DMX mode */
if (!(mode == RING_MODE_WAIT_DMX_BREAK || mode == RING_MODE_WAIT_DMX))
wait_for_ticks(5); wait_for_ticks(5);
if((int16_t)TIM3->CNT > (int16_t)led_val) { if((int16_t)TIM3->CNT > (int16_t)led_val) {
led_val = 0u; led_val = 0u;