2020-05-20 01:48 AM
I am using the stm32f103 and trying to display a text on a screen via DMA to the USART 2 device. I guess I will turn on the usart2 TX dma (DMAT) request when I need it and turn it off after the current transmission is complete (i.e. in the DMA1_Channel7_IRQHandler). That is, when I call the write_data_voltage_to_nextion(DEFINED IN MY CODE) USART2 DMATx function is enabled and DMA1 will serve it, same thing when I call the write_data_current_to_nextion(DEFINED IN MY CODE) USART2 DMAT function is enabled and DMA1 will serve it. The problem is that the display is correct when I execute one of two functions but if I execute the two functions successively nothing is displayed. The DMA1_Channel7_IRQHandler is not served after all.
I spent a lot of time on this problem, but I couldn't get it to work. Somebody help me, thank you. Here's my code...
uint32_t bff[40] = {'\0'};
void DMA1_USART2_TX_Config(void)
{
DMA_DeInit(DMA1_Channel7);
RCC-> APB2ENR |= RCC_APB2ENR_AFIOEN;
RCC-> APB2RSTR =0;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* DMA */
DMA_InitTypeDef DMA_InitStruct;
DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)(&(USART2->DR));
DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)&bff[0];
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStruct.DMA_BufferSize = sizeof(bff);
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;
DMA_InitStruct.DMA_Priority =DMA_Priority_Low;// DMA_Priority_High;// DMA_Priority_VeryHigh;
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel7, &DMA_InitStruct);
USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
DMA_ITConfig( DMA1_Channel7,DMA_IT_TC,ENABLE );
DMA_Cmd(DMA1_Channel7, DISABLE);
NVIC_EnableIRQ(DMA1_Channel7_IRQn);
}
void DMA1_Channel7_IRQHandler(void)//TX
{
if(DMA_GetITStatus(DMA1_IT_TC7))
{
DMA_ClearITPendingBit(DMA1_IT_GL7);
DMA_Cmd(DMA1_Channel7, DISABLE);
}
}
void Nextion_usart_DMA(uint8_t *data, uint32_t data_len)/**uint16_t**/
{
memcpy(bff , data, data_len);
/* Restart DMA Channel*/
DMA_ITConfig(DMA1_Channel7, DMA_IT_TC, DISABLE);
USART_DMACmd(USART2, USART_DMAReq_Tx, DISABLE);
DMA_Cmd(DMA1_Channel7, DISABLE);
DMA1_Channel7->CNDTR = data_len;
DMA_ITConfig(DMA1_Channel7, DMA_IT_TC, ENABLE);
USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
DMA_Cmd(DMA1_Channel7, ENABLE);
}
void write_data_courant_to_nextion(float data) /*principale*/
{
float_to_string(data,i_buf,Get_float_len(&data),3);
nextion_usart_DMA(I_T2_CONTROL_TYPE);
}
void write_data_voltage_to_nextion(float data) /*principale*/
{
float_to_string(data,v_buf,Get_float_len(&data),3);
nextion_DMA(V_T0_CONTROL_TYPE);
}
2020-05-20 03:03 AM
Code doesn't even look to be compilable, or consistent.
Doesn't check if DMA is active.
2020-05-20 03:16 AM
clive I would like to make two transmissions in a row like the following.
{
write_data_voltage_to_nextion(value_tension ) ;
write_data_courant_to_nextion(value_courant) ;
}
When I am under the debugger, we observe the first successful transmission, but the second transmission fails,
the problem is that the DMA1_Channel7_IRQHandler() function is not called between the two transmissions. I do not understand why. Do you know why ?