使用下面的测试代码,我正在尝试使用Watching the I/O view 中USART
的数据寄存器发送数据,即使我正在设置它也永远不会设置。我的代码或模拟器有什么问题吗?xmega128a3u
simulator
Atmel Studio.
#include <avr/io.h>
#include <avr/interrupt.h>
#define bscale 0
#define bsel 0x0003 //250kbps
#define packetFormat (USART_SBMODE_bm | USART_CHSIZE_8BIT_gc | USART_PMODE_DISABLED_gc)
uint8_t n;
int main(void)
{
//ALLOW PORTB AND PORTF TO BE WRITTEN TO! TURNS OFF JTAG
CCP = 0xD8; //Allow Protected IO changing
MCU_MCUCR = 0x1;
//CRYSTAL SETUP
OSC_XOSCCTRL = OSC_FRQRANGE_12TO16_gc | OSC_XOSCSEL_XTAL_16KCLK_gc; // 16Mhz Crystal
OSC_CTRL |= OSC_XOSCEN_bm;
while(!(OSC_STATUS & OSC_XOSCRDY_bm)); //Wait for crystal to stabilize.
CCP = CCP_IOREG_gc;
CLK_CTRL = CLK_SCLKSEL_XOSC_gc;
//END CRYSTAL SETUP
cli();
//Enable Interrupts
USARTF0.CTRLA = USART_TXCINTLVL_LO_gc | USART_DREINTLVL_LO_gc;
//Enable transmitter
USARTF0.CTRLB = USART_TXEN_bm;
PMIC.CTRL |= PMIC_LOLVLEX_bm;
//Set baud
USARTF0.BAUDCTRLB = bscale;
USARTF0.BAUDCTRLA = bsel;
//Set packet format
USARTF0.CTRLC = packetFormat;
sei();
while (1)
{
if(n < 255) {
USARTF0.DATA = n;
} else {
n = 0;
}
}
}
ISR(USARTF0_TXC_vect) {
n++;
}
ISR(USARTF0_DRE_vect) {
n++;
}