Good morning everyone, First, introduce me in the forum! I am a Spanish electrical engineer, with great experience in the design of PCBs and in the programming of microcontrollers, but this is the first time that I have been involved in an ATMM ARM and I am having some problem. The first thing is that I do not like to work with ASF libraries that are already incorporated in the atmel studio. Therefore, I am programming the micro through registers. My problems, specifically with the USART, given that for some reason, I do not know if configuration or to address the interruciones generated by this peripheral with send me data through the port, I attach code for if you see any erratum. The first doubt I have is how to set the transmission speed to be the usual one; 9600 without parity and stop bit, and also how to manage the interrupt routines. As you can see in the code for now I only sent the ASCII 'A' character, but I can not complete the transmission successfully. Any ideas?
Thanks in advance.
#include "sam.h" uint16_t i; int main(void) { SystemInit(); GCLK->PCHCTRL[22].bit.GEN=0; GCLK->PCHCTRL[22].bit.CHEN=1; //REG_GCLK_PCHCTRL22= GCLK_PCHCTRL_GEN_GCLK0 | GCLK_PCHCTRL_CHEN; MCLK->APBCMASK.bit.SERCOM3_=1; MCLK->APBAMASK.bit.OSCCTRL_=1; //PA22 UART TX SERCOM3 //PA23 UART RX //PA24 CAN0TX //PA25 CAN0RX //Led PA15 //Button PA28 PORT->Group[0].DIRSET.reg=PORT_PA22;//TX as Output PORT->Group[0].DIRCLR.reg=PORT_PA23;//RX as Input PORT->Group[0].PINCFG[22].bit.INEN=1; //Tx input avialable PORT->Group[0].PINCFG[23].bit.INEN=1; //Rx input avialable PORT->Group[0].PINCFG[22].bit.PMUXEN=1;//Enable multiplexing PORT->Group[0].PINCFG[23].bit.PMUXEN=1;//Enable multiplexing PORT->Group[0].PMUX[11].bit.PMUXE=0x02;//Type D PORT->Group[0].PMUX[11].bit.PMUXO=0x02;//Type D SERCOM3->USART.CTRLA.bit.ENABLE = 0; //Disable USART for config SERCOM3->USART.CTRLA.bit.MODE = 1; //Set clock mode to internal clock SERCOM3->USART.CTRLA.bit.CMODE = 0; //Set clock to be asynchronous with bus clk SERCOM3->USART.CTRLA.bit.RXPO = 1; //Select Rx pin to be PAD[1] SERCOM3->USART.CTRLA.bit.TXPO = 0; //Select Tx pin to be PAD[0] SERCOM3->USART.CTRLA.bit.DORD = 1; //Set data order (MSB first) SERCOM3->USART.CTRLA.bit.FORM = 1; //Frame settings enable SERCOM3->USART.CTRLA.bit.SAMPR=0; SERCOM3->USART.BAUD.bit.BAUD = 64563; SERCOM3->USART.CTRLB.bit.CHSIZE = 0; //Config the char size field to 8 bit SERCOM3->USART.CTRLB.bit.RXEN = 1; //Enable Receiver SERCOM3->USART.CTRLB.bit.TXEN = 1; //Enable transmitter while (SERCOM3->USART.SYNCBUSY.bit.CTRLB); //wait NVIC_EnableIRQ(SERCOM3_IRQn); SERCOM3->USART.INTENSET.reg = SERCOM_USART_INTFLAG_RXC; SERCOM3->USART.CTRLA.reg |= SERCOM_USART_CTRLA_ENABLE; while(SERCOM3->USART.SYNCBUSY.reg & SERCOM_USART_SYNCBUSY_ENABLE); PORT->Group[0].PINCFG[28].bit.PULLEN=1; PORT->Group[0].PINCFG[28].bit.INEN=1; PORT->Group[0].DIR.reg=(0<<28); PORT->Group[0].OUT.reg=PORT_PA28; PORT->Group[0].DIRSET.reg=PORT_PA15;//Config as output while(1){ PORT->Group[0].OUTSET.reg=PORT_PA15;//Put pin as HIGH for(i=0;i<50000;i++); PORT->Group[0].OUTCLR.reg=PORT_PA15;//Put pin as LOW for(i=0;i<50000;i++); while(!SERCOM3->USART.INTFLAG.bit.DRE); SERCOM3->USART.DATA.reg = 'A'; while(!SERCOM3->USART.INTFLAG.bit.TXC); } } void SERCOM3_Handler(){ /*if (SERCOM3->USART.INTFLAG.bit.TXC) { SERCOM3->USART.INTENCLR.bit.TXC=1; }*/ }