打印
[Atmel]

每天跟我读点资料:SAM D SERCOM USART 配置7

[复制链接]
1878|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ddllxxrr|  楼主 | 2016-3-21 20:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
4.2.6 扩展USART管脚初使化
     SERCOM2 USART线连到EXT2连接头。edbg_usart_pin_init函数将初始化PA08PA09管脚到SERCOM外设功能。
/* External connector(SERCOM2) pin initialization */
void ext_usart_pin_init(void)
{
/* PA08 and PA09 set into peripheral function C */
pin_set_peripheral_function(PINMUX_PA08D_SERCOM2_PAD0);
pin_set_peripheral_function(PINMUX_PA09D_SERCOM2_PAD1);
}
Ext_usart_pin_init 函数调pin_set_peripheral_function分配I/O连线到PA08PA09进入到SERCOM外设功能。
4.2.7 外部USART初始化
Ext_usart_init函数初始化USART功能通过配置控制寄存器,波特率寄存器,和设置相应的中断标志。
/* External connector(SERCOM2) UART initialization */
void ext_usart_init(void)
{
uint16_t baud_value;
baud_value = calculate_baud_value(USART_BAUD_RATE,sys-tem_gclk_chan_get_hz(SERCOM2_GCLK_ID_CORE),
USART_SAMPLE_NUM);
/* By setting the DORD bit LSB is transmitted first and setting the RXPO bit as 1 correspond-ing SERCOM PAD[1] will be used for data reception RXD, PAD[0] will be used as TxD pin by set-ting TXPO bit as 0,16x over-sampling is selected by setting the SAMPR bit as 0,
Generic clock is enabled in all sleep modes by setting RUNSTDBY bit as 1,
USART clock mode is selected as USART with internal clock by setting MODE bit into 1.
*/
SERCOM2->USART.CTRLA.reg = SERCOM_USART_CTRLA_DORD |
SERCOM_USART_CTRLA_RXPO(0x1) |
SERCOM_USART_CTRLA_TXPO(0x0) |
SERCOM_USART_CTRLA_SAMPR(0x0)|
SERCOM_USART_CTRLA_RUNSTDBY |
SERCOM_USART_CTRLA_MODE_USART_INT_CLK ;
/* baud register value corresponds to the device communication baud rate */
SERCOM2->USART.BAUD.reg = baud_value;
/* 8-bits size is selected as character size by setting the bit CHSIZE as 0,
TXEN bit and RXEN bits are set to enable the Transmitter and receiver*/
SERCOM2->USART.CTRLB.reg = SERCOM_USART_CTRLB_CHSIZE(0x0) |
SERCOM_USART_CTRLB_TXEN |
SERCOM_USART_CTRLB_RXEN ;
/* synchronization busy */
while(SERCOM2->USART.SYNCBUSY.bit.CTRLB);
/* SERCOM2 handler enabled */
system_interrupt_enable(SERCOM2_IRQn);
/* receive complete interrupt set */
SERCOM2->USART.INTENSET.reg = SERCOM_USART_INTFLAG_RXC;
/* SERCOM2 peripheral enabled */
SERCOM2->USART.CTRLA.reg |= SERCOM_USART_CTRLA_ENABLE;
/* synchronization busy */
while(SERCOM2->USART.SYNCBUSY.reg & SERCOM_USART_SYNCBUSY_ENABLE);
}
这节同4.2.4节一样把SERCOM2 PADS配置为USART,并使能SERCOM2的中断功能。
4.2.8 SERCOM中断处理
   下面代码是SERCOM2SERCOM3在应用程序中的中断处理.
   /*ext_usart handler*/
void SERCOM2_Handler()
{
if (SERCOM2->USART.INTFLAG.bit.RXC){
ext_rx_data = SERCOM2->USART.DATA.reg;
if (SERCOM3->USART.INTFLAG.bit.DRE)
{
SERCOM3->USART.DATA.reg = ext_rx_data;
}
}
}
/*edbg_usart handler*/
void SERCOM3_Handler()
{
if (SERCOM3->USART.INTFLAG.bit.RXC){
edbg_rx_data = SERCOM3->USART.DATA.reg;
if (SERCOM2->USART.INTFLAG.bit.DRE)
{
SERCOM2->USART.DATA.reg = edbg_rx_data;
}
}
}
在这个应用中,从PC终端1发出的字符通过EDBG USART(SERCOM3)SAM D21 Xplained pro(发送者)。这个字符将通过连接两个板子的EXT2被另一个SAM D21 Xplained pro (接收)
现在从SAM D21 Xplained pro(接收者)接到的字符将到达另一个PC终端2
总而言之,字符从PC终端1通过SAM D21 板子接收PC终端2的字符。同样地PC终端2也可通过相同路径接收PC终端1的字符。

相关下载

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2399

主题

6964

帖子

68

粉丝