AI8051U DMA UART2/3/4实例程序uart不能收发 | 已解决
诸位大佬,上午好官方提供的串口1使用DMA中断模式与电脑收发测试功能正常。
但,串口2/3/4 使用DMA中断模式与电脑收发测试功能不正常,没研究明白,哪位大佬指导下,感谢!
串口1234DMA例程:
参考代码仅有这些,工作异常乱码:P0M1 = 0x00; P0M0 = 0x00; //设置为准双向口
问题出现在IO的初始化上,配置成下面的就可以了
P0M1 = 0x05; /* 0000_0101 M10:00-in or out 01-out 10-input 11-kailou mode */
P0M0 = 0xfa; /* 1111_1010 */
P0PU = 0x05; /* 0000_0101 R=5k */
P0 = 0x0f; /* 0000_1111 */ 你好, 我有一個問題, 一直沒法解決
原本使用
stc8g2k64s4和 stc8h8k64
和式一直很正常
最近改用stc32g8k64
大部份問題都解決
但有個問題 uart2,一直解決不了
我把程序簡化到最簡單
發現 uart2 正常
但只要一加上
TMOD=0x01;
uart2 就無法收法正常 #include "stc32g.h"
sbit RS_485_2 = P4^1;
//===============================================================
//GLOBAL VARIABLE
//===============================================================
bit bU0TX_2 = 0;
//------------------------------------------------------------------------
//UART222.11849600USE TIME21T
//------------------------------------------------------------------------
void Uart2_Init(void) //9600bps@22.1184MHz
{
S2CON = 0x50; //8 bits and variable baudrate
AUXR |= 0x04; //imer clock is 1T mode
T2L = 0xC0; //Initial timer value
T2H = 0xFD; //Initial timer value
AUXR |= 0x10; //Timer2 start run
}
void UART2_Isr() interrupt 8
{
// UART2TI
if (S2CON & 0x02)
{
S2CON &= ~0x02;
bU0TX_2 = 0;
}
// UART2 RI
if (S2CON & 0x01)
{
S2CON &= ~0x01;
}
}
void PutByte2(unsigned char n_temp0)
{
bU0TX_2 = 1;
S2BUF = n_temp0;
while(bU0TX_2)
{
;
}
}
void IO_init(void)
{
P0M0 = 0X00;P0M1 = 0X00;
P1M0 = 0X00;P1M1 = 0X00;
P2M0 = 0X00;P2M1 = 0X00;
P3M0 = 0X00;P3M1 = 0X00;
P4M0 = 0X00;P4M1 = 0X00;
P5M0 = 0X00;P5M1 = 0X00;
P6M0 = 0X00;P6M1 = 0X00;
P7M0 = 0X00;P7M1 = 0X00;
}
void main()
{
// STC32G8K64
WTST = 0; //設置程式指令延時參數,賦值為0可將CPU執行指令的速度設置為最快
EAXFR = 1; //擴展寄存器(XFR)訪問使能/
CKCON = 0; //提高訪問XRAM速度
IO_init();
Uart2_Init();
ES2=1;
//-----------------------------
TMOD=0x10;
//-----------------------------
EA = 1;
RS_485_2=1;
PutByte2('2');
PutByte2('2');
PutByte2('2');
RS_485_2=0;
while(1)
{
}
}
STC芯片,我也只是刚刚使用AI8051U,还不熟悉,不然也不会一些基础性的东西都不熟悉。
TMOD=0x01; 看下规格书涉及到哪些?这个寄存器看看关联性,操作的话建议是位操作,尽可能不影响其他部分。 Build target 'UART1'
compiling UART1.c...
UART1.c(25): error C318: can't open file '..\..\comm\AI8051U.h'
UART1.c(47): error C67: 'SBUF': undefined identifier
UART1.c(48): error C67: 'TI': undefined identifier
UART1.c(49): error C67: 'TI': undefined identifier
UART1.c(71): error C67: 'WTST': undefined identifier
UART1.c(72): error C67: 'EAXFR': undefined identifier
UART1.c(73): error C67: 'CKCON': undefined identifier
UART1.c(75): error C67: 'P0M1': undefined identifier
UART1.c(75): error C67: 'P0M0': undefined identifier
UART1.c(76): error C67: 'P1M1': undefined identifier
UART1.c(76): error C67: 'P1M0': undefined identifier
UART1.c(77): error C67: 'P2M1': undefined identifier
UART1.c(77): error C67: 'P2M0': undefined identifier
UART1.c(78): error C67: 'P3M1': undefined identifier
UART1.c(78): error C67: 'P3M0': undefined identifier
UART1.c(79): error C67: 'P4M1': undefined identifier
UART1.c(79): error C67: 'P4M0': undefined identifier
UART1.c(80): error C67: 'P5M1': undefined identifier
UART1.c(80): error C67: 'P5M0': undefined identifier
UART1.c(81): error C67: 'P6M1': undefined identifier
UART1.c(81): error C67: 'P6M0': undefined identifier
UART1.c(82): error C67: 'P7M1': undefined identifier
UART1.c(82): error C67: 'P7M0': undefined identifier
UART1.c(93): error C67: 'EA': undefined identifier
UART1.c(104): error C67: 'DMA_UR1R_DONEH': undefined identifier
UART1.c(104): error C67: 'DMA_UR1R_DONE': undefined identifier
UART1.c(106): error C67: 'DMA_UR1T_AMT': undefined identifier
UART1.c(107): error C67: 'DMA_UR1T_AMTH': undefined identifier
UART1.c(110): error C67: 'DMA_UR1R_CR': undefined identifier
UART1.c(112): error C67: 'DMA_UR1T_CR': undefined identifier
UART1.c(113): error C67: 'DMA_UR1R_CR': undefined identifier
UART1.c(137): error C67: 'DMA_UR1T_CFG': undefined identifier
UART1.c(138): error C67: 'DMA_UR1T_STA': undefined identifier
UART1.c(139): error C67: 'DMA_UR1T_AMT': undefined identifier
UART1.c(140): error C67: 'DMA_UR1T_AMTH': undefined identifier
UART1.c(141): error C67: 'DMA_UR1T_TXAH': undefined identifier
UART1.c(142): error C67: 'DMA_UR1T_TXAL': undefined identifier
UART1.c(143): error C67: 'DMA_UR1T_CR': undefined identifier
UART1.c(145): error C67: 'DMA_UR1R_CFG': undefined identifier
UART1.c(146): error C67: 'DMA_UR1R_STA': undefined identifier
UART1.c(147): error C67: 'DMA_UR1R_AMT': undefined identifier
UART1.c(148): error C67: 'DMA_UR1R_AMTH': undefined identifier
UART1.c(149): error C67: 'DMA_UR1R_RXAH': undefined identifier
UART1.c(150): error C67: 'DMA_UR1R_RXAL': undefined identifier
UART1.c(151): error C67: 'DMA_UR1R_CR': undefined identifier
UART1.c(165): error C67: 'T2R': undefined identifier
UART1.c(166): error C67: 'T2_CT': undefined identifier
UART1.c(167): error C67: 'T2x12': undefined identifier
UART1.c(168): error C67: 'T2H': undefined identifier
UART1.c(169): error C67: 'T2L': undefined identifier
UART1.c(170): error C67: 'ET2': undefined identifier
UART1.c(171): error C67: 'T2R': undefined identifier
UART1.c(188): error C67: 'S1BRT': undefined identifier
UART1.c(195): error C67: 'TR1': undefined identifier
UART1.c(196): error C67: 'S1BRT': undefined identifier
UART1.c(197): error C67: 'T1_CT': undefined identifier
UART1.c(198): error C67: 'T1x12': undefined identifier
UART1.c(199): error C67: 'TMOD': undefined identifier
UART1.c(200): error C67: 'TH1': undefined identifier
UART1.c(201): error C67: 'TL1': undefined identifier
UART1.c(202): error C67: 'ET1': undefined identifier
UART1.c(203): error C67: 'TR1': undefined identifier
UART1.c(207): error C67: 'SCON': undefined identifier
UART1.c(207): error C67: 'SCON': undefined identifier
UART1.c(210): error C67: 'REN': undefined identifier
UART1.c(212): error C67: 'S1_S1': undefined identifier
UART1.c(213): error C67: 'S1_S0': undefined identifier
UART1.c(215): error C67: 'UR1TOCR': undefined identifier
UART1.c(216): error C67: 'UR1TOTL': undefined identifier
UART1.c(217): error C67: 'UR1TOTH': undefined identifier
UART1.c(218): error C67: 'UR1TOTE': undefined identifier
UART1.c(245): error C67: 'UR1TOSR': undefined identifier
UART1.c(248): error C67: 'UR1TOSR': undefined identifier
UART1.c(263): error C67: 'DMA_UR1T_STA': undefined identifier
UART1.c(265): error C67: 'DMA_UR1T_STA': undefined identifier
UART1.c(268): error C67: 'DMA_UR1T_STA': undefined identifier
UART1.c(270): error C67: 'DMA_UR1T_STA': undefined identifier
UART1.c(273): error C67: 'DMA_UR1R_STA': undefined identifier
UART1.c(275): error C67: 'DMA_UR1R_STA': undefined identifier
UART1.c(278): error C67: 'DMA_UR1R_STA': undefined identifier
UART1.c(280): error C67: 'DMA_UR1R_STA': undefined identifier
assembling isr.asm...
目标未创建
编译一下 还缺头文件 天宁宁 发表于 2024-11-30 06:56
Build target 'UART1'
compiling UART1.c...
UART1.c(25): error C318: can't open file '..\..\comm\AI805 ...
我去
页:
[1]