以前用 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;
}
}
__HAL_UART_GET_FLAG (&huart1, UART_FLAG_FE) 少个参数, 多的那个参数是啥, 也没注释啊.
define __HAL_UART_GET_FLAG (__HANDLE__, __FLAG__, __OPERATING__) (__OPERATING__ (__HANDLE__, __FLAG__) )
这个__OPERATING__参数是个啥.