#include const uint8_t LED = PC13; #define DebugPort Serial1 /* UART1 */ const uint8_t LENGTH = 96; uint8_t buffer[LENGTH]; volatile bool dataReady = 0; #define PERIPH_CLOCK1 36000000L #define BAUDRATE 230400 void initLD() { // GPIO //enable clock access to GPIOA RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; //Enable clock access to alternate function RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; //Confgiure PA2 as output maximum speed to 50MHz // and alternate output push-pull mode GPIOA->CRL |= GPIO_CRL_MODE2; GPIOA->CRL |= GPIO_CRL_CNF2_1; GPIOA->CRL &= ~GPIO_CRL_CNF2_0; // Configure PA3 as Input floating // Set mode to be input GPIOA->CRL &= ~(GPIO_CRL_MODE3); GPIOA->CRL |= GPIO_CRL_CNF3_0; GPIOA->CRL &= ~GPIO_CRL_CNF3_1; // Don't remap the pins AFIO->MAPR &= ~AFIO_MAPR_USART2_REMAP; // USART2 //enable clock access to USART2 RCC->APB1ENR |= RCC_APB1ENR_USART2EN; //Transmit and receive enable USART2->CR1 |= USART_CR1_TE | USART_CR1_RE; // Enable DMA for receiver USART2->CR3 |= USART_CR3_DMAR; // Set baudrate USART2->BRR |= ((PERIPH_CLOCK1 + BAUDRATE/2) / BAUDRATE); // DMA RCC->AHBENR |= RCC_AHBENR_DMA1EN; // Memory increment, circular mode, transfer complete interrupt enable DMA1_Channel6->CCR |= DMA_CCR_MINC | DMA_CCR_CIRC | DMA_CCR_TCIE; NVIC_EnableIRQ(DMA1_Channel6_IRQn); // Set the peripheral address to be USART2->DR DMA1_Channel6->CPAR = (uint32_t)&USART2->DR; DMA1_Channel6->CMAR = (uint32_t)buffer; DMA1_Channel6->CNDTR = LENGTH; DMA1_Channel6->CCR |= DMA_CCR_EN; //Enable UART USART2->CR1 |= USART_CR1_UE; } void DMA1_Channel6_IRQHandler(void) { digitalWrite(LED, !digitalRead(LED)); if(DMA1->ISR & DMA_ISR_TCIF6) { dataReady = 1; DMA1->IFCR = DMA_IFCR_CTCIF6; } } void setup() { DebugPort.begin(230400); delay(3000); DebugPort.println("ahoj"); pinMode(LED, OUTPUT); initLD(); } void loop() { DebugPort.println("x"); delay(1000); /* if (DMA1->ISR & DMA_ISR_HTIF6) { DMA1->IFCR = DMA_IFCR_CTCIF6 | DMA_IFCR_CHTIF6 | DMA_IFCR_CGIF6; digitalWrite(LED, !digitalRead(LED)); } */ }