cancel
Showing results for 
Search instead for 
Did you mean: 

stm8l151g4 DMA USART recieve only once

Esten.11
Associate

Hi.

i'm try using USART1 and recieve bytes with DMA from SBUS transmitter.

. But have strange problem - i'm recive only once and later DMA IRQ TC2 never occure. I'm try many variants - all not help me(((

Here my some code -

#define USART_DMA_CHANNEL_RX   DMA1_Channel2
#define USART_DMA_CHANNEL_TX   DMA1_Channel1
#define USART_DMA_FLAG_TCRX    (uint16_t)DMA1_FLAG_TC2
#define USART_DMA_FLAG_TCTX    (uint16_t)DMA1_FLAG_TC1
#define USART_DR_ADDRESS       (uint16_t)0x5231  /* USART1 Data register Address */
#define USART_TX_BUF_ADDR (uint32_t)(&dma_pack)
 
uint8_t dma_pack[40];
 
static void USART_Config( void )
{
    CLK_PeripheralClockConfig( CLK_Peripheral_USART1, ENABLE );
 
    SYSCFG_REMAPPinConfig( REMAP_Pin_USART1TxRxPortA, ENABLE );
 
    GPIO_ExternalPullUpConfig( GPIOA, GPIO_Pin_3, ENABLE );
    GPIO_ExternalPullUpConfig( GPIOA, GPIO_Pin_2, ENABLE );
 
    USART_Init( USART1, ( uint32_t )100000, USART_WordLength_9b, USART_StopBits_2,
                USART_Parity_Even, ( USART_Mode_TypeDef )( USART_Mode_Rx ) );
 
    USART_Cmd( USART1, ENABLE);
}
 
static void DMA_Config( void )
{
    DMA_GlobalDeInit();
 
    DMA_DeInit( USART_DMA_CHANNEL_TX );
    DMA_DeInit( USART_DMA_CHANNEL_RX );
 
    CLK_PeripheralClockConfig( CLK_Peripheral_DMA1, ENABLE );
 
    DMA_Init( USART_DMA_CHANNEL_RX, USART_TX_BUF_ADDR, USART_DR_ADDRESS, 
    SBUS_PACKET_SIZE,  DMA_DIR_PeripheralToMemory, DMA_Mode_Normal, 
    DMA_MemoryIncMode_Inc, DMA_Priority_Low, DMA_MemoryDataSize_Byte );
 
    DMA_ITConfig( USART_DMA_CHANNEL_RX, DMA_ITx_TC, ENABLE );
    DMA_Cmd( USART_DMA_CHANNEL_RX, ENABLE );
    USART_DMACmd( USART1, USART_DMAReq_RX, ENABLE );
 
    DMA_GlobalCmd( ENABLE );
 
}
 
 
INTERRUPT_HANDLER( DMA1_CHANNEL2_3_IRQHandler, 3 )
{
    if ( DMA_GetFlagStatus( DMA1_FLAG_TC2 ) != RESET )
 
        DMA_Cmd( DMA1_Channel2, DISABLE );
        DMA_SetCurrDataCounter( DMA1_Channel2, 25 );
        DMA_Cmd( DMA1_Channel2, ENABLE );
        DMA_ClearFlag( DMA1_FLAG_TC2 );
        
    }
}
 
main()
{
CLK_SYSCLKDivConfig( CLK_SYSCLKDiv_1 );
USART_Config();
DMA_Config();
while(1);
}

But IRQ dma2 fired only once and not later and program always stay in while loop.

There no problem in UART sender - uart-usb reciever working good and always getting SBUS packets..

Where maybe problem?

2 REPLIES 2
Esten.11
Associate

This is because USART overrun error - but why? Using circle dma not helping. Bug?

WilkoL
Senior

Are you sure you want to use 100 kbits/s, 9 bits data, even parity and 2 stopbits? It seems very unusual.

115200 bps, 8 bits, no parity and 1 stopbit perhaps?