5 W806 W801串口DMX512收发问题

发布于 2022-05-11 16:26:39

以前用51和STM32的单片机做过,但是这个刚开始玩,库没介绍不知咋弄.
DMX512_RDM协议.pdf
6a7c0e61d5bf5a396c1e795f51ea4571.pdf
stm32实现DMX512协议发送与接收.PDF

这个是STM32的
void USART1_IRQHandler(void)
{

uint8_t SBUF;
if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_FE) == SET)
{             
    SBUF = huart1.Instance->DR;
    __HAL_UART_CLEAR_FLAG(&huart1,UART_FLAG_FE);
    __HAL_UART_CLEAR_FLAG(&huart1,UART_FLAG_PE);        
    if(SBUF == 0)
    {
        DMX_SIGN = 1;
        CHK_SIGN = 0;
        AddrCont = 0; 
        DmxRec   = 0;                        
    }
    else 
    {
        DMX_SIGN = 0;
        CHK_SIGN = 0;                   
    }
}     

else if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_RXNE) == SET)
{

    SBUF = huart1.Instance->DR;   
    __HAL_UART_CLEAR_FLAG(&huart1,UART_IT_RXNE);
    __HAL_UART_CLEAR_FLAG(&huart1,UART_FLAG_RXNE);   
    if(DMX_SIGN == 1)
    {
        switch(SBUF) 
        {
            case 0:
                CHK_SIGN = 1;
                Slave    = 0;
                DmxSign  = 200;
                Addrbuf  = DmxAddr;
                DmxRec   = 0;
                DMX_SIGN = 0;
                AddrCont = 0;                                            
                break;
        
            case 1:            
                CHK_SIGN = 1;
                Slave    = 1;
                DmxSign  = 200;
                DmxRec   = 0;
                Addrbuf  = 1; 
                DMX_SIGN = 0;
                AddrCont = 0;                                            
                break;                        
        }
    }
    else 
    {
        if(CHK_SIGN == 1)
        {                        
            AddrCont++;                                
            if(AddrCont == (Addrbuf+DmxRec))
            {
                dmx[DmxRec] = SBUF;
                if(++DmxRec >=64 ){DmxRec=0;CHK_SIGN = 0;}
            }                        
        }
    }        

}
HAL_UART_IRQHandler(&huart1);
}
这个是51的
void IRQ_Uart0 (void) interrupt 4 using 3
{

RI = 0;
if(RB8==0)
{
    Dmx_Startcode = 0;        
    DmxCont=0x0000;    
    Dmx_Space = 1;            
    return;                
}         
else if(RB8 == 1)
{
    if(Dmx_Space == 1)
    {              
        if(SBUF == 0)
        {
            Dmx_Startcode = 1;
            Dmx_Space = 0;                
            Dmxsig = 200;
            DmxCont=0x0000;
        }
        else Dmx_Startcode = 0;                
    }        
    else if(Dmx_Startcode == 1)
    {        
            DmxCont++; 
            Dmxdat[DmxCont] = SBUF;                                    
            if(DmxCont>=512)DmxCont=0;
    }                
}                  

}
这个是51发送的:
void DmxOut(void)
{

uint8_t i;
P31 = 0;Delay88us();
P31 = 1;Delay8us();
TB8 = 1;
SBUF = 0x00; while(TI==0);TI=0;
for(i=0;i<16;i++)
{
    if(Black==0)SBUF=out[i];
    else SBUF = 0;
    while(TI==0);TI=0;
}    

}

查看更多

关注者
0
被浏览
141
1 个回答
ZYQ
ZYQ 2022-05-11
往前看,不回头!!!

W806 单机库的话跟STM32 hal库的使用方法基本一致,你参考着做就可以了

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览