AnsweredAssumed Answered

STM32F103ZE RS485 DMA communication problem

Question asked by friedlander.ivan on Oct 31, 2011
Latest reply on Nov 1, 2011 by Clive One

HI!

I have a problem with the following code ..
After a few hours to several days. The maximum was to 14 days
Data transmission stops working. Receive and transmit works in one task. (BACNET protocol)
For DMA uses internal RAM.
Receive and other tasks
works further.

 

void USART3_SendData(unsigned char buffer[], int Len) {
    if (Len > 500) {
        Len = 500;
    }
    memcpy(TxBuffer3Out, buffer, Len);
    DMA_InitTypeDef DMA_InitStructure5;
    DMA_DeInit(DMA1_Channel2);
    DMA_InitStructure5.DMA_PeripheralBaseAddr = USART3_DR_Base;
    DMA_InitStructure5.DMA_MemoryBaseAddr = TxBuffer3Out;
    DMA_InitStructure5.DMA_DIR = DMA_DIR_PeripheralDST;
    DMA_InitStructure5.DMA_BufferSize = Len;
    DMA_InitStructure5.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure5.DMA_MemoryInc = DMA_MemoryInc_Enable;
    DMA_InitStructure5.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
    DMA_InitStructure5.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
    DMA_InitStructure5.DMA_Mode = DMA_Mode_Normal;
    DMA_InitStructure5.DMA_Priority = DMA_Priority_Low;
    DMA_InitStructure5.DMA_M2M = DMA_M2M_Disable;
    DMA_ITConfig(DMA1_Channel2, DMA_IT_TC, ENABLE);
    DMA_ITConfig(DMA1_Channel2, DMA_IT_TE, ENABLE);
    DMA_Init(DMA1_Channel2, &DMA_InitStructure5);
    USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
    DMA_ClearFlag(DMA1_FLAG_TC2);
    NVIC_EnableIRQ(DMA1_Channel2_IRQn);
    RS485_rts_enable(true);
    DMA1_Channel2->CCR |= DMA_CCR2_EN;

    OS_FlagID flag;
    start:

    flag = CoWaitForSingleFlag(USART3txFlag, 500);
    if (flag != E_OK && flag != E_TIMEOUT) {
         goto start;
    }

    CoTimeDelay(0, 0, 0, 20);
    RS485_rts_enable(false);
}

void DMA1_Channel2_IRQHandler(void) {//USART3 TX
    if (DMA_GetITStatus(DMA1_IT_HT2) == SET) {
        DMA_ClearITPendingBit(DMA1_IT_HT2);
    } else if (DMA_GetITStatus(DMA1_IT_TC2) == SET) {
        DMA_ClearITPendingBit(DMA1_IT_TC2);
        USART_ITConfig(USART3, USART_IT_TC, ENABLE);
    } else if (DMA_GetITStatus(DMA1_IT_TE2) == SET) {
        DMA_ClearITPendingBit(DMA1_IT_TE2);
    }
    return;
}

 

void USART3_IRQHandler(void) {
    if (USART_GetITStatus(USART3, USART_IT_TC) == SET) {
        USART_ClearITPendingBit(USART3, USART_IT_TC);
        USART_ITConfig(USART3, USART_IT_TC, DISABLE);

        CoEnterISR();
        isr_SetFlag(USART3txFlag);
        CoExitISR();
        return;
    }

}

 

Any idea??

Thanks!!

ArSi

Outcomes