嵌入式编程中的中断与链接器问题解析
1. 串口通信与循环缓冲区程序
1.1 程序功能概述
该程序旨在通过循环缓冲区将 “Hello World!” 字符串不断发送到串口。它使用了一个循环缓冲区来存储待发送的字符,并通过中断机制实现字符的异步发送。
1.2 关键代码分析
1.2.1 字符写入函数 myPutchar
void myPutchar(const char ch)
{
// Wait until there is room.
while (buffer.nCharacters == BUFFER_SIZE)
continue;
buffer.data[buffer.putIndex] = ch;
++buffer.putIndex;
if (buffer.putIndex == BUFFER_SIZE)
buffer.putIndex = 0;
// We've added another character.
++buffer.nCharacters;
// Now we're done.
// Enable the interrupt (or reenable it).
uartHandle.Instance->CR1 |= USART_CR1_TXEIE;
}
此函数的执行步骤如下:
1. 等待缓冲区有空间。
2. 将字符存入缓冲
超级会员免费看
订阅专栏 解锁全文
1783

被折叠的 条评论
为什么被折叠?



