用在通信及ADC上,使用DMA循環式架構。利用DMA上的計數器做為FIFO控制。
其中USART1_BUFFER_SIZE,要設定在DMA的大小中。
 USART1_Buffer[]也是DMA所使用的。
unsigned short last_count;
void Reset_USART1_Buffer(void)
{
    last_count = DMA_GetCurrDataCounter(DMA2_Stream5);
}
int Get_USART1_Value(unsigned char *Value)
{
    unsigned short current_count;
    int  pos;
    current_count = DMA_GetCurrDataCounter(DMA2_Stream5);
    if ( current_count != last_count )
    {
        pos = USART1_BUFFER_SIZE - last_count;
        *Value = USART1_Buffer[pos];
        last_count--;
        if (last_count <= 0)
        {
            last_count = USART1_BUFFER_SIZE;
        }
        return -1;
    }
    else
    {
        return 0;
    }
}
因為已用DMA,軟體過一段時間去收就好了,完全無需使用中斷。
沒有留言:
張貼留言