Very short bit in USART with AVR128DA64

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

 

I'm finally finding some time to play with my AVRDA's (always used mega's before) and I'm puzzled with some USART output
 

About half of the time the sent byte has a bit that is far too short, never the same bit, never the same actual/expected time ratio

Here is a code reproducing the problem, inspired by the Microchip example at Github (https://github.com/MicrochipTech/avr128da48-usart-example)
I attached the measured output too

#include <avr/io.h>
#include <util/delay.h>

#define USART_BAUD_RATE(BAUD_RATE)     ((float)(64 * F_CPU / (16 * (float)BAUD_RATE)) + 0.5)
void USART_sendChar(char c){
    while(!(USART0.STATUS & USART_DREIF_bm)){}
    USART0.TXDATAL = c;
}

void main(){
  PORTA.DIRSET = PIN0_bm;
  _PROTECTED_WRITE(CLKCTRL.OSCHFCTRLA, CLKCTRL_FREQSEL_8M_gc);
  _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, 0);

  USART0.BAUD = (uint16_t)(USART_BAUD_RATE(115200));
  USART0.CTRLC = USART_SBMODE_bm | USART_CHSIZE0_bm | USART_CHSIZE1_bm;
  PORTA.DIRSET = PIN0_bm;
  USART0.CTRLB |= USART_TXEN_bm;

  while(1){
    _delay_us(150);
    USART_sendChar(0x55);
  }
}

I tried with FREQSEL from 2 to 24MHz but nothing helped

I guess it's my fault but I can't see what I'm missing here

Attachment(s): 

This topic has a solution.
Last Edited: Tue. Aug 18, 2020 - 12:34 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you run your code on my 128DA28 it outputs a perfect waveform. When I connect it to the PC terminal, only 0x55 appears.

Check the hardware and observation method.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks like you are right, setting my scope at 8MHz fixes the "problem"

Thanks for trying the code

I normally check everything before asking for help online but this time I trusted too much the scope and didn't even try to actually read the data...

 

Last Edited: Tue. Aug 18, 2020 - 12:34 AM