General-P 发表于 2022-9-7 22:06

【雅特力AT32WB415系列蓝牙BLE 5.0 MCU测评】4.0 串口通信 Printf测试

<div class='showpostmsg'><p style="text-align: center;"><span style="font-size:20px;">串口通信 Printf测试</span></p>

<p><span style="font-size:18px;">一、板载通信资源</span></p>

<p><span style="font-size:18px;">&nbsp; &nbsp;</span><span style="font-size:16px;"> 雅特力AT32WB415开发板具有较为丰富通信外设资源:有3路串口通信接口,IIC,SPI,CAN,USB2.0等诸多接口。</span></p>

<p><span style="font-size:16px;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size:18px;">二、程序分析</span></p>

<p><span style="font-size:18px;">&nbsp; &nbsp; </span><span style="font-size:16px;">1、串口初始化</span></p>

<p><span style="font-size:16px;">&nbsp; &nbsp; 该部分代码原理和ST差不多,学习过ST的库函数开发者基本都能理解</span></p>

<p><span style="font-size:16px;">&nbsp;&nbsp;&nbsp;&nbsp;</span></p>

<pre>
<code class="language-cpp">void uart_print_init(uint32_t baudrate)
{
gpio_init_type gpio_init_struct;

/* enable the uart and gpio clock */
crm_periph_clock_enable(PRINT_UART_CRM_CLK, TRUE);
crm_periph_clock_enable(PRINT_UART_TX_GPIO_CRM_CLK, TRUE);

gpio_default_para_init(&amp;gpio_init_struct);

/* configure the uart tx pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type= GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = PRINT_UART_TX_PIN;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(PRINT_UART_TX_GPIO, &amp;gpio_init_struct);

/* configure uart param */
usart_init(PRINT_UART, baudrate, USART_DATA_8BITS, USART_STOP_1_BIT);
usart_transmitter_enable(PRINT_UART, TRUE);
usart_enable(PRINT_UART, TRUE);
}</code></pre>

<p>&nbsp; &nbsp; <span style="font-size:16px;">2、Printf重定向函数</span></p>

<pre>
<code class="language-cpp">/* support printf function, usemicrolib is unnecessary */
#if (__ARMCC_VERSION &gt; 6000000)
__asm (".global __use_no_semihosting\n\t");
void _sys_exit(int x)
{
    x = x;
}
/* __use_no_semihosting was requested, but _ttywrch was */
void _ttywrch(int ch)
{
    ch = ch;
}
FILE __stdout;
#else
#ifdef __CC_ARM
#pragma import(__use_no_semihosting)
struct __FILE
{
    int handle;
};
FILE __stdout;
void _sys_exit(int x)
{
    x = x;
}
/* __use_no_semihosting was requested, but _ttywrch was */
void _ttywrch(int ch)
{
    ch = ch;
}
#endif
#endif</code></pre>

<p>&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-size:16px;">记得要添加stdio.h的头文件,不然程序会出现报错</span>,最后记得勾选<span style="font-size:16px;">上这个,不然将无法通信</span></p>

<p><span style="font-size:16px;">&nbsp; &nbsp;</span></p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>

lishiwen 发表于 2022-9-8 14:38

<p>蓝牙的地址是0x000000的、在复位是应该有一个时序的问题,需要先复位MCU在复位蓝牙、我们手机的蓝牙必须使用类似LightBlue这类的软件才可以连接,直接是无法连接上。</p>

Tecksay 发表于 2022-9-8 17:00

<p>不错不错&nbsp; &nbsp;刚好要这个</p>

<p>看起来挺容易的&nbsp; &nbsp; 不知道调试时会不会出错</p>
页: [1]
查看完整版本: 【雅特力AT32WB415系列蓝牙BLE 5.0 MCU测评】4.0 串口通信 Printf测试