以前用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__參數是個啥.