Gast
#1774889
Hallo Zusammen,
als neuling, ich experiementiere mit dem Xplain Daten an PC via UARTC0
senden. Dank dem Hyper termninal bekomme ich der gesendete Buschtabe,
aber immer mit einem ungewünschten Buschtabe dazu. Z.B. wenn ich 'A'
sende, bekomme ich 'AP'. Um so zu sagen dass ich etwas anderes bekomme.
Ich benutze Xplain mit ATXmeg128A , Alle H/C-Files sind beigefügt.
hier der Code:
#define F_CPU 32000000UL
#include "avr_compiler.h"
#include "port_driver.h"
#include "pmic_driver.h"
#include "clksys_driver.h"
#include "TC_driver.h"
#include "usart_driver.h"
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#define USART USARTC0
// USART data struct
USART_data_t USART_data;
void Clk_Init()
{
CLKSYS_Enable( OSC_RC32MEN_bm );
CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );
do {} while ( CLKSYS_IsReady( OSC_RC32MRDY_bm ) == 0 );
CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_RC32M_gc );
}
//Initialize UART
void USARTC0_Init( void)
{
// PD3 (TXD0) as output, Transmitter
PORTC.DIRSET = PIN3_bm;
// PD2 (RXD0) as input, Receiver
PORTC.DIRCLR = PIN2_bm;
// Use USARTC0 and initialize buffers.
USART_InterruptDriver_Initialize(&USART_data, &USART,
USART_DREINTLVL_LO_gc);
// USARTC0, 8 Data bits, No Parity, 1 Stop bit.
USART_Format_Set(USART_data.usart, USART_CHSIZE_8BIT_gc,
USART_PMODE_DISABLED_gc, false);
//Enable TXD interrupt
USART_TxdInterruptLevel_Set(&USARTC0, USART_RXCINTLVL_LO_gc);
/* Set Baudrate to 9600bps:
* Use the default I/O clock frequency that is 32 MHz.
* Do not use the baudrate scale factor
*
* Baudrate select = (1/(16*(((I/O clock frequency)/Baudrate)-1)
* = 207
*/
USART_Baudrate_Set(&USART,207,0);
// Enable both RX and TX.
USART_Rx_Enable(&USART);
USART_Tx_Enable(&USART);
// Enable PMIC interrupt level low
PMIC.CTRL |= PMIC_LOLVLEX_bm;
}
ISR(USARTC0_RXC_vect)
{
USART_RXComplete(&USART_data);
}
//Data register empty interrupt service routine.
ISR(USARTC0_DRE_vect)
{
USART_DataRegEmpty(&USART_data);
}
int main (void)
{
Clk_Init();
USARTC0_Init();
PMIC.CTRL |= PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm;
sei();
while(1)
{
while(!USART_IsTXDataRegisterEmpty(&USART));
USART_TXBuffer_PutByte(&USART_data,'A');
}
}
Der "USART_TXBuffer_PutByte" ist ein bool funktion, kann der, der
Fehler verusachen?
Danke
Olive