问题:用Microchip Studio 中的代码生成器配置串口,接收中断配置,但是生成的代码里找不到中断入口函数,无法通过中断来接收串口的数据,发送OK。因为现有项目使用的都是代码生成器生成的,故没有使用ASF库里面的串口函数,**大家可以指点迷津。
串口参数配置:
生成的相关代码:
int8_t USART_0_init()
{ if (!hri_sercomusart_is_syncing(SERCOM0, SERCOM_USART_SYNCBUSY_SWRST)) {
uint32_t mode = SERCOM_USART_CTRLA_MODE(1);
if (hri_sercomusart_get_CTRLA_reg(SERCOM0, SERCOM_USART_CTRLA_ENABLE)) {
hri_sercomusart_clear_CTRLA_ENABLE_bit(SERCOM0);
hri_sercomusart_wait_for_sync(SERCOM0, SERCOM_USART_SYNCBUSY_ENABLE);
}
hri_sercomusart_write_CTRLA_reg(SERCOM0, SERCOM_USART_CTRLA_SWRST | mode);
}
hri_sercomusart_wait_for_sync(SERCOM0, SERCOM_USART_SYNCBUSY_SWRST); hri_sercomusart_write_CTRLA_reg(SERCOM0,
1 << SERCOM_USART_CTRLA_DORD_Pos /* Data Order: enabled */
| 0 << SERCOM_USART_CTRLA_CMODE_Pos /* Communication Mode: disabled */
| 0 << SERCOM_USART_CTRLA_FORM_Pos /* Frame Format: 0 */
| 0 << SERCOM_USART_CTRLA_SAMPA_Pos /* Sample Adjustment: 0 */
| 2 << SERCOM_USART_CTRLA_SAMPR_Pos /* Sample Rate: 2 */
| 0 << SERCOM_USART_CTRLA_IBON_Pos /* Immediate Buffer Overflow Notification: disabled */
| 0 << SERCOM_USART_CTRLA_RUNSTDBY_Pos /* Run In Standby: disabled */
| 1 << SERCOM_USART_CTRLA_MODE_Pos); /* Operating Mode: enabled */ hri_sercomusart_write_CTRLA_TXPO_bf(SERCOM0, SERCOM0_TXPO);
hri_sercomusart_write_CTRLA_RXPO_bf(SERCOM0, SERCOM0_RXPO); hri_sercomusart_write_CTRLB_reg(SERCOM0,
1 << SERCOM_USART_CTRLB_RXEN_Pos /* Receiver Enable: enabled */
| 1 << SERCOM_USART_CTRLB_TXEN_Pos /* Transmitter Enabl: enabled */
| 0 << SERCOM_USART_CTRLB_PMODE_Pos /* Parity Mode: disabled */
| 0 << SERCOM_USART_CTRLB_ENC_Pos /* Encoding Format: disabled */
| 0 << SERCOM_USART_CTRLB_SFDE_Pos /* Start of Frame Detection Enable: disabled */
| 0 << SERCOM_USART_CTRLB_COLDEN_Pos /* Collision Detection Enable: disabled */
| 0 << SERCOM_USART_CTRLB_SBMODE_Pos /* Stop Bit Mode: disabled */
| 0); /* Character Size: 0 */ hri_sercomusart_write_BAUD_reg(SERCOM0, SERCOM0_BAUD_RATE); // hri_sercomusart_write_RXPL_reg(SERCOM0,0); /* Receive Pulse Length: 0 */ // hri_sercomusart_write_DBGCTRL_reg(SERCOM0,0 << SERCOM_USART_DBGCTRL_DBGSTOP_Pos); /* Debug Stop Mode: disabled */ hri_sercomusart_write_INTEN_reg(SERCOM0,
0 << SERCOM_USART_INTENSET_ERROR_Pos /* Error Interrupt Enable: disabled */
| 0 << SERCOM_USART_INTENSET_RXBRK_Pos /* Receive Break Interrupt Enable: disabled */
| 0 << SERCOM_USART_INTENSET_CTSIC_Pos /* Clear to Send Input Change Interrupt Enable: disabled */
| 0 << SERCOM_USART_INTENSET_RXS_Pos /* Receive Start Interrupt Enable: disabled */
| 1 << SERCOM_USART_INTENSET_RXC_Pos /* Receive Complete Interrupt Enable: enabled */
| 0 << SERCOM_USART_INTENSET_TXC_Pos /* Transmit Complete Interrupt Enable: disabled */
| 0 << SERCOM_USART_INTENSET_DRE_Pos); /* Data Register Empty Interrupt Enable: disabled */ hri_sercomusart_write_CTRLA_ENABLE_bit(SERCOM0, 1 << SERCOM_USART_CTRLA_ENABLE_Pos); /* Enable: enabled */ return 0;
}
void USART_0_PORT_init()
{ gpio_set_pin_function(TX, PINMUX_PA04D_SERCOM0_PAD0); gpio_set_pin_function(RX, PINMUX_PA05D_SERCOM0_PAD1);
} void USART_0_enable()
{
hri_sercomusart_set_CTRLA_ENABLE_bit(SERCOM0);
} void system_init(void)
{
init_mcu(); // GPIO on PB30 gpio_set_pin_level(LED,
// <y> Initial level
// <id> pad_initial_level
// <false"> Low
// <true"> High
true); // Set pin direction to output
gpio_set_pin_direction(LED, GPIO_DIRECTION_OUT); gpio_set_pin_function(LED, GPIO_PIN_FUNCTION_OFF); USART_0_CLOCK_init();
USART_0_init();
USART_0_PORT_init();
USART_0_enable();
delay_driver_init(); //WDT_0_init();
}
|