我尝试将STM8S103F3 UART1与PC COM1端口一起使用(19200波特,非奇偶校验
8位数据,1个停止位),但有一些数据丢失。
void UART_Init(void)
{
// [2] 310 UART1 INITIALIZATION
// Step1)[2] 346定义字长(UART_CR1中的M位)
UART1-> CR1& = ~UART1_CR1_M; // M = 0(8个数据位)
// Step2)[2] 349定义UART_CR3中的停止位数
UART1-> CR3& = ~UART1_CR3_STOP; // STOP [1:0] = 00(1个停止位)
//步骤3)[2] 316选择所需的波特率
// 1)波特率= 19200
// Tx / Rx波特率= fMASTER / UART_DIV
// =(16MHz / 8)/ 19200
// = 2000 / 19.2
// = 104.16
//〜= 104 = 068h
UART1-> BRR2 = 0x08; // 19200波特
UART1-> BRR1 = 0x06;
//步骤4)启用发送器模式(UART_CR2中的TEN位)
UART1-> CR2 | = UART1_CR2_TEN; //传输启用
} / * UART_Init * /
u8 bUART_TxCnt;
u8 * pbUART_Tx; //系统发送指针
void UART_TxByte(u8 bByte)
{
pbUART_Tx =& bByte;
bUART_TxCnt = 1;
UART1-> CR2 | = UART1_CR2_TIEN;
} / * UART_TxByte * /
@far @interrupt void UART1_TX_IRQHandler(void)
{
if(bUART_TxCnt)
{
//在设置新数据之前是否需要检查TC位?
UART1-> DR = * pbUART_Tx ++;
bUART_TxCnt--;
}
其他
UART1-> CR2& = ~UART1_CR2_TIEN;
}
void main(void)
{
u8 bData;
UART_Init();
enableInterrupts();
for(;;)
{
for(bData ='0'; bData< ='9'; bData ++)
UART_TxByte(BDATA);
} / *用于无限循环* /
} / * main * /
PC PComm实用程序丢失了一些数据作为附件。
我错过了什么吗?
Q1)发送数据寄存器空和传输完成中断事件之间有什么区别?
Q2)在将数据写入UART_DR寄存器之前是否需要检查TC位?
Q3)每个传输的数据是否都会产生TXE和TC中断?
Q4)是否可以仅使用TC位中断进行传输?
[此消息由以下内容编辑:jeffrey.chang168于18-12-2009 12:57]
[此消息编辑:jeffrey.chang168于18-12-2009 12:58]
[此消息由以下人员编辑:jeffrey.chang168于18-12-2009 17:02发表]
[此消息由:jeffrey.chang168于20-12-2009 03:29编辑]
以上来自于谷歌翻译
以下为原文
I tried to use STM8S103F3 UART1 with PC COM1 port (19200 baud, Non-parity
8-bit data, 1 stop bit), but there are some data lost.
void UART_Init (void)
{
// [2]310 UART1 INITIALIZATION
// Step1) [2]346 To define the word length (M bit in UART_CR1)
UART1->CR1 &= ~UART1_CR1_M; // M=0 (8 data bits)
// Step2) [2]349 To define the number of stop bits in UART_CR3
UART1->CR3 &= ~UART1_CR3_STOP; // STOP[1:0]=00 (1 stop bit)
// Step3) [2]316 To select the desired baud rate
// 1) Baud rate = 19200
// Tx/Rx baud rate = fMASTER / UART_DIV
// = (16MHz / 8) / 19200
// = 2000 / 19.2
// = 104.16
// ~= 104 = 068h
UART1->BRR2 = 0x08; // 19200 Baud
UART1->BRR1 = 0x06;
// Step4) To enable transmitter mode (TEN bit in UART_CR2)
UART1->CR2 |= UART1_CR2_TEN; // transmit enable
} /* UART_Init */
u8 bUART_TxCnt;
u8 *pbUART_Tx; // system transmit pointer
void UART_TxByte (u8 bByte)
{
pbUART_Tx = &bByte;
bUART_TxCnt = 1;
UART1->CR2 |= UART1_CR2_TIEN;
} /* UART_TxByte */
@far @interrupt void UART1_TX_IRQHandler (void)
{
if (bUART_TxCnt)
{
// Is it necessary to check the TC bit before setup new data ?
UART1->DR = *pbUART_Tx++;
bUART_TxCnt--;
}
else
UART1->CR2 &= ~UART1_CR2_TIEN;
}
void main (void)
{
u8 bData;
UART_Init();
enableInterrupts();
for (;;)
{
for (bData = '0'; bData <= '9'; bData++)
UART_TxByte(bData);
} /* for endless loop */
} /* main */
PC PComm utility lost some data as attachment.
Did I miss anything ?
Q1) What's the difference between the transmit data register empty and tramsmission complete interrupt events ?
Q2) Is it necessary to check the TC bit before writing data to the UART_DR register ?
Q3) Does every transmitted data generate TXE and TC interrupts ?
Q4) Is it possible to use TC bit interrupt ONLY for transmission ?
[ This message was edited by: jeffrey.chang168 on 18-12-2009 12:57 ]
[ This message was edited by: jeffrey.chang168 on 18-12-2009 12:58 ]
[ This message was edited by: jeffrey.chang168 on 18-12-2009 17:02 ]
[ This message was edited by: jeffrey.chang168 on 20-12-2009 03:29 ]
我尝试将STM8S103F3 UART1与PC COM1端口一起使用(19200波特,非奇偶校验
8位数据,1个停止位),但有一些数据丢失。
void UART_Init(void)
{
// [2] 310 UART1 INITIALIZATION
// Step1)[2] 346定义字长(UART_CR1中的M位)
UART1-&gt; CR1&amp; = ~UART1_CR1_M; // M = 0(8个数据位)
// Step2)[2] 349定义UART_CR3中的停止位数
UART1-&gt; CR3&amp; = ~UART1_CR3_STOP; // STOP [1:0] = 00(1个停止位)
//步骤3)[2] 316选择所需的波特率
// 1)波特率= 19200
// Tx / Rx波特率= fMASTER / UART_DIV
// =(16MHz / 8)/ 19200
// = 2000 / 19.2
// = 104.16
//〜= 104 = 068h
UART1-> BRR2 = 0x08; // 19200波特
UART1-&gt; BRR1 = 0x06;
//步骤4)启用发送器模式(UART_CR2中的TEN位)
UART1-> CR2 | = UART1_CR2_TEN; //传输启用
} / * UART_Init * /
u8 bUART_TxCnt;
u8 * pbUART_Tx; //系统发送指针
void UART_TxByte(u8 bByte)
{
pbUART_Tx =&amp; bByte;
bUART_TxCnt = 1;
UART1-&gt; CR2 | = UART1_CR2_TIEN;
} / * UART_TxByte * /
@far @interrupt void UART1_TX_IRQHandler(void)
{
if(bUART_TxCnt)
{
//在设置新数据之前是否需要检查TC位?
UART1-&gt; DR = * pbUART_Tx ++;
bUART_TxCnt--;
}
其他
UART1-&gt; CR2&amp; = ~UART1_CR2_TIEN;
}
void main(void)
{
u8 bData;
UART_Init();
enableInterrupts();
for(;;)
{
for(bData ='0'; bData&lt; ='9'; bData ++)
UART_TxByte(BDATA);
} / *用于无限循环* /
} / * main * /
PC PComm实用程序丢失了一些数据作为附件。
我错过了什么吗?
Q1)发送数据寄存器空和传输完成中断事件之间有什么区别?
Q2)在将数据写入UART_DR寄存器之前是否需要检查TC位?
Q3)每个传输的数据是否都会产生TXE和TC中断?
Q4)是否可以仅使用TC位中断进行传输?
[此消息由以下内容编辑:jeffrey.chang168于18-12-2009 12:57]
[此消息编辑:jeffrey.chang168于18-12-2009 12:58]
[此消息由以下人员编辑:jeffrey.chang168于18-12-2009 17:02发表]
[此消息由:jeffrey.chang168于20-12-2009 03:29编辑]
以上来自于谷歌翻译
以下为原文
I tried to use STM8S103F3 UART1 with PC COM1 port (19200 baud, Non-parity
8-bit data, 1 stop bit), but there are some data lost.
void UART_Init (void)
{
// [2]310 UART1 INITIALIZATION
// Step1) [2]346 To define the word length (M bit in UART_CR1)
UART1->CR1 &= ~UART1_CR1_M; // M=0 (8 data bits)
// Step2) [2]349 To define the number of stop bits in UART_CR3
UART1->CR3 &= ~UART1_CR3_STOP; // STOP[1:0]=00 (1 stop bit)
// Step3) [2]316 To select the desired baud rate
// 1) Baud rate = 19200
// Tx/Rx baud rate = fMASTER / UART_DIV
// = (16MHz / 8) / 19200
// = 2000 / 19.2
// = 104.16
// ~= 104 = 068h
UART1->BRR2 = 0x08; // 19200 Baud
UART1->BRR1 = 0x06;
// Step4) To enable transmitter mode (TEN bit in UART_CR2)
UART1->CR2 |= UART1_CR2_TEN; // transmit enable
} /* UART_Init */
u8 bUART_TxCnt;
u8 *pbUART_Tx; // system transmit pointer
void UART_TxByte (u8 bByte)
{
pbUART_Tx = &bByte;
bUART_TxCnt = 1;
UART1->CR2 |= UART1_CR2_TIEN;
} /* UART_TxByte */
@far @interrupt void UART1_TX_IRQHandler (void)
{
if (bUART_TxCnt)
{
// Is it necessary to check the TC bit before setup new data ?
UART1->DR = *pbUART_Tx++;
bUART_TxCnt--;
}
else
UART1->CR2 &= ~UART1_CR2_TIEN;
}
void main (void)
{
u8 bData;
UART_Init();
enableInterrupts();
for (;;)
{
for (bData = '0'; bData <= '9'; bData++)
UART_TxByte(bData);
} /* for endless loop */
} /* main */
PC PComm utility lost some data as attachment.
Did I miss anything ?
Q1) What's the difference between the transmit data register empty and tramsmission complete interrupt events ?
Q2) Is it necessary to check the TC bit before writing data to the UART_DR register ?
Q3) Does every transmitted data generate TXE and TC interrupts ?
Q4) Is it possible to use TC bit interrupt ONLY for transmission ?
[ This message was edited by: jeffrey.chang168 on 18-12-2009 12:57 ]
[ This message was edited by: jeffrey.chang168 on 18-12-2009 12:58 ]
[ This message was edited by: jeffrey.chang168 on 18-12-2009 17:02 ]
[ This message was edited by: jeffrey.chang168 on 20-12-2009 03:29 ]
举报