ATTiny1614 Uart concerns

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

Hi freaks!

 

I have began work with the new attiny series that currently has no examples online that I can find. Tiny's in general don't appear to have any examples in AS7 either.

 

I have been trying to get Rx working. I can verify that the signal going in is at 3.3v and looks perfect on the scope for timing, nice square edges and correct bit settings.

 

My code thus far is as follows:

#define BAUD_RATE 103
void Uart_Init(void)
{
    //PB2 - Tx.
    //PB3 - Rx.
	PORTB.DIRSET |= (1<<2);
	PORTB.OUTSET |= (1<<2);
	
	//don't use interrupts, don't want to delay the pwm...
	USART0.CTRLC = 0x03;	//set character size to 8. parity = none. stop bits = 1. async usart.
	USART0.BAUDH = (uint8_t)(BAUD_RATE>>8);	//baudRegVal = 64*clk/(s*baud), where in normal mode s = 16. in x2 rate, s = 8.
	USART0.BAUDL = (uint8_t)(BAUD_RATE);
	USART0.CTRLB = (1<< RXEN) | (1<< TXEN);	//enable rx and tx
}

static void Uart_ServiceRx(void)
{	
	if ((PORTB.IN & (1<<3)) && (USART0.STATUS & (1<<7)))
	{
		uint8_t byte = 0;
		
		byte = USART0.RXDATAL;
		
		if (byte != 0)
		{
			volatile int x = 6;
			x++;
		}
	}
}

Polling the "UART0.STATUS" register for the highest bit is supposed to be an Rx Receive complete flag and is set high when there is unread data. But my unread data is ALWAYS 0x00.

 

Since the microchip takeover I have noticed that all of the new chips now have errata, which is a little concerning, but nonetheless they usually have work arounds. Reading the Errata, they state this very issue:

40.1.7 USART
    ​1 –
    Frame error on previous message may cause false start bit detection
    If receiving a frame with RXDATAH.FERR set and reading the RXDATAL
    before the RxD line goes high, will trigger a false start bit detection.
    Fix/Workaround:
    Wait for the RxD pin to go high before reading RXDATA, for instance by
    polling the bit in PORTn.IN where the RxD pin is located.

Thus trying to read the state of my pin before trying to read the data. I also use the "volatile int x" statement for a garunteed breakpoint to capture any non-zero value to no avail.

 

Has anyone had any experience with this series of chips that could either shed some light on where I can go from here or perhaps have a working example of it?

 

-Ryan.

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

Buy the XMINI or XPRO for the Tiny817. Develop / experiment on that board. Far easier than connecting an external ATMEL-ICE.
.
From memory, the USART works fine. But your current code is pointless. The Optimiser will notice this.
.
David.

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

Disappointingly, the ATTiny817 doesn't appear to suffer from this issue. It is not listed in its Errata. This was my next move if I couldn't find a way around the above issue.

 

Pointless, how so?

 

If you mean because I am not doing anything with my variables you would typically be correct, however since I have defined a separate variable as a volatile based on a condition of the useless on, the compiler will not optimise it out. I have verified that as well by debugging my code.

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

Have you checked the tx just to make sure you baudrate etc is what you expect?

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

Beating a dead horse for a few hours scraping through the datasheet resulted in nothing.

 

Came in this morning, 2 minutes later rx/tx is working.

 

This series of ATTiny's use a special peripheral clock that runs at F_CPU/6. thus using the 16M internal RC, it runs at 2.66Mhz. This was the illusive value that the datasheet touches on but goes against the old avr implementation :(

 

Kartman wrote:

Have you checked the tx just to make sure you baudrate etc is what you expect?

 

This was the issue. I didn't touch the baud rate value because I was expecting to at least get junk characters, but apparently not!

 

Nonetheless, its working now :)

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

ryanafleming wrote:
I have began work with the new attiny series that currently has no examples online that I can find. Tiny's in general don't appear to have any examples in AS7 either.
Any examples would be in Atmel START though couldn't find any tinyAVR 1-series USART examples in Atmel START.

There is USART code in Atmel START for tiny1614.

http://start.atmel.com/

 

"Dare to be naïve." - Buckminster Fuller