Documentation on start frame detection interrupt for ATmega328PB

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

Hi all,

 

I'm looking for documentation on start frame interrupt functionality on the ATmega328PB.

 

There is an off-hand mention of this capability in section 24.9.4 Start Frame Detection in the ATmega328PB datasheet, however there appears to be no documentation (that I can find) on the registers involved in working with this interrupt.

 

For example, the datasheet says:

 

The USART start frame detection works in both asynchronous and synchronous modes. It is enabled by
writing the Start Frame Detection Enable bit (SFDE). If the USART Start Interrupt Enable (RXSIE) bit is
set, the USART Receive Start Interrupt is generated immediately when start is detected.

Unfortunately, that is the only mention of SFDE and/or RXSIE in the entire datasheet

 

An app-note from avr called AVR42783: Using USART to Wake Up ATmega328PB from Sleep Mode basically just uselessly copies and pastes the above paragraph, with no further explanation.  It then shows some abstracted sample code where no register manipulation is shown, and instructs you to download the full source code from Atmel START.

 

Once you download the code from Atmel START, and start navigating around in it, you find the following:

static void uart_init(void)
{
	// USART0
	UBRR0H = UBRRH_VALUE;
	UBRR0L = UBRRL_VALUE;

	// Enable RX and TX and set interrupts on RX complete
	UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);

	// 8-bit, 1 stop bit, no parity, asynchronous UART
	UCSR0C
	    = (1 << UCSZ01) | (1 << UCSZ00) | (0 << USBS0) | (0 << UPM01) | (0 << UPM00) | (0 << UMSEL01) | (0 << UMSEL00);

	// Enable Start Frame Detection
	UCSR0D = (0 << RXSIE) | (1 << SFDE);

	// Initialize the in and out buffer for the UART
	ring_buffer_out = ring_buffer_init(out_buffer, BUFFER_SIZE);
	ring_buffer_in  = ring_buffer_init(in_buffer, BUFFER_SIZE);
}

So, looks like the proper register name is UCSR0D...

 

There is no ISR defined for the start frame detection interrupt, so I assume this code example simply uses the ISR to wake the device from sleep.

 

By typing in stuff in Atmel studio, auto-completion seems to think that the ISR vector symbol for start frame detection is USART0_START_vect.  Also, going to implementation of OCSR0D brings me to iom328pb.h header file which has the following code grouped together:

 

#define UCSR0D  _SFR_MEM8(0xC3)
#define SFDE    5
#define RXS     6
#define RXSIE   7

 

I wonder what the RXS bit represents?  I assume the other abbreviations break down as follows:

 

- SFDE --> start frame detection enable bit

- RXSIE --> RX start frame interrupt enable bit

- RXS -->  ???

 

Being a relative newbie to AVR programming, I wonder: did I do well in figuring this stuff out?  Is this really the only documentation on start frame detection?  Is there really no actual formal register description of UCSR0D available to developers?

 

Thanks!

 

 

This topic has a solution.

I love the smell of burning silicon in the morning

Last Edited: Thu. Jul 19, 2018 - 10:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd say that you did better than the average bear! Good job in ferreting it out.

 

Maybe like other interrupts, RXS is the testable bit that indicates RX Start, independent of the interrupt (that is, testable by polling)?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Wed. Jul 18, 2018 - 08:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jaza_tom wrote:
Unfortunately, that is the only mention of SFDE and/or RXSIE in the entire datasheet

At this point, I've only read that far.  But that isn't much different than the doc for any similar AVR8 interrupts, is it?  The condition is signaled by setting the flag.  If you enable the corresponding xxxIE bit, then the ISR is invoked.  For veteran AVR8 people, it sounds OK so far.  Now back to reading the rest of the post...

 

jaza_tom wrote:
Unfortunately, that is the only mention of SFDE and/or RXSIE in the entire datasheet

I guess.  If I'm curious about an AVR feature, I'll read the associated chapter.  And at least scroll through the "Register Description".  When looking for it, this would pop out:

Did you find a typo?  Probably.

 

Do you need Atmel Start to do your investigation?  Hmmmm--I guess it would depend on what your toolchain of choice is.  If my toolchain has support, I'd build/generate a test program, and examine the chip-include file.

 

jaza_tom wrote:
There is no ISR defined for the start frame detection interrupt, so I assume this code example simply uses the ISR to wake the device from sleep. By typing in stuff in Atmel studio, auto-completion seems to think that the ISR vector symbol for start frame detection is USART0_START_vect.

I don't quite know what you are getting at here.  Let's peek at the list of interrupt vectors in the datasheet...

Again, there is a "small print" statement somewhere about the "this is repersentative and there might be multiple instances with a specific instance number bla bla bla..."

 

 

I think the rest of your post is covered in the UCSR0D/UCSR1D piece of the datasheet.

 

It certainly can be daunting with an AVR model with hundreds of I/O registers with many/most having multiple bits in them.  Perhaps try a read through the chip-include file along with the datasheet chapters for the various peripheral subsystems.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

The PB model of the M328 is fairly new model, so it would not surprise me if little info is available on the interwebs, where the M328P has been around and is quite popular!

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

ka7ehk wrote:
I'd say that you did better than the average bear!

I think the problem is looking at the datasheet from a wrong direction.

jaza_tom's picture

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Hmm...

 

In the latest version of the datasheet, chapter 25 only goes to 25.8:

 

 

And there is no mention of UCSRnD in either the USART or USARTSPI chapters.

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

The debugger seems to know about UCSRnD:

 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

YAY, I'M NOT CRAZY AFTER ALL!cool

 

 

 

Greg_Muth wrote:

Hmm...

 

In the latest version of the datasheet, chapter 25 only goes to 25.8:

 

 

And there is no mention of UCSRnD in either the USART or USARTSPI chapters.

 

theusch wrote:

jaza_tom wrote:
Unfortunately, that is the only mention of SFDE and/or RXSIE in the entire datasheet

At this point, I've only read that far.  But that isn't much different than the doc for any similar AVR8 interrupts, is it?  The condition is signaled by setting the flag.  If you enable the corresponding xxxIE bit, then the ISR is invoked.  For veteran AVR8 people, it sounds OK so far.  Now back to reading the rest of the post...

 

jaza_tom wrote:
Unfortunately, that is the only mention of SFDE and/or RXSIE in the entire datasheet

I guess.  If I'm curious about an AVR feature, I'll read the associated chapter.  And at least scroll through the "Register Description".  When looking for it, this would pop out:

Did you find a typo?  Probably.

 

Do you need Atmel Start to do your investigation?  Hmmmm--I guess it would depend on what your toolchain of choice is.  If my toolchain has support, I'd build/generate a test program, and examine the chip-include file.

 

jaza_tom wrote:
There is no ISR defined for the start frame detection interrupt, so I assume this code example simply uses the ISR to wake the device from sleep. By typing in stuff in Atmel studio, auto-completion seems to think that the ISR vector symbol for start frame detection is USART0_START_vect.

I don't quite know what you are getting at here.  Let's peek at the list of interrupt vectors in the datasheet...

Again, there is a "small print" statement somewhere about the "this is repersentative and there might be multiple instances with a specific instance number bla bla bla..."

 

 

I think the rest of your post is covered in the UCSR0D/UCSR1D piece of the datasheet.

 

It certainly can be daunting with an AVR model with hundreds of I/O registers with many/most having multiple bits in them.  Perhaps try a read through the chip-include file along with the datasheet chapters for the various peripheral subsystems.

 

@theusch can you post that older (correcter) datasheet with the juicy scoop on the start frame detect registers!?

I love the smell of burning silicon in the morning

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

Here is the vector definition from iom328pb.h:

 

/* USART0 Start frame detection */
#define USART0_START_vect            _VECTOR(26)
#define USART0_START_vect_num        26

 

EDIT:

 

In case you're wondering, the path for the file above is:

C:/Program Files (x86)/Atmel/Studio/7.0/packs/atmel/ATmega_DFP/1.2.209/include/avr/iom328pb.h

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

Last Edited: Thu. Jul 19, 2018 - 01:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Last post...

 

This compiles without error:

 

/*
 * USART_Frame_Start.c
 *
 * Created: 7/18/2018 6:23:50 PM
 * Author : greg
 */

#include <avr/interrupt.h>
#include <avr/io.h>


int main(void)
{
    /* Replace with your application code */
    while (1)
    {
    }
}


ISR(USART0_START_vect)
{
    
}


ISR(USART0_RX_vect)
{
    
}


ISR(USART0_TX_vect)
{
    
}


ISR(USART0_UDRE_vect)
{
    
}


 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

Well, I did some testing using mEDBG mode and it appears as though the ISR for start frame detection never gets invoked, howver if I put the device into sleep mode, I can successfully wake it using start-frame detection.

 

So, I guess this interrupt can only be used to wake up a device from sleep, and not to actually trigger an ISR

 

Whatever, it does what I want cheeky

I love the smell of burning silicon in the morning

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

Greg_Muth wrote:
And there is no mention of UCSRnD in either the USART or USARTSPI chapters.

So the quotes/snapshots I gave are really Fake News?!?  I should be in politics.

 

Now you are going to make me look.  I quoted the Rev. C dated 10/15 so indeed nearly three years old.  No wonder OP is confused.  Was the feature removed?  Errata?  Change history has a mention?  Stay tuned while I get the latest datasheet...

[edit]  Indeed, no apparent mention of any change in that feature in rev history or errata.  As a guess, the "convertor" person started with the wrong version?

 

jaza_tom wrote:
So, I guess this interrupt can only be used to wake up a device from sleep, and not to actually trigger an ISR

I find that quite hard to believe.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Jul 19, 2018 - 01:46 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think what we have here is the writer of the datasheets editor not double checking the writers work.

 

From page 276 in the datasheet I found on the website:

 

The device is not looking for a START FRAME, but a single BIT. and indeed it appears that the sole purpose of this is to wake the AVR.

 

JIm

 

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

 

 

App Note...

 

AVR42783: Using USART to Wake Up
ATmega328PB from Sleep Mode

 

...has more info

 

As does...

 

AT15007: Differences between ATmega328/P and
ATmega328PB

 

 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

ki0bk wrote:

The PB model of the M328 is fairly new model,...

 

The first datasheet is dated 2015 so not that new.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Here is the first version of the Atmel datasheet which has the register info in it...

 

 

Attachment(s): 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Brian Fairchild wrote:
The first datasheet is dated 2015 so not that new.

Although the datasheet is dated then, when was the common public able to get hands on the beasties?   Wasn't that the model made out of unobtanium, or was that the '324PB?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Jul 19, 2018 - 02:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Wasn't that the model made out of unobtanium, or was that the '324PB?

 

Both.  With the 324PB being the most elusive beast.  I seem to recall you were rabidly looking for them.

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

The DS for 48-88-168pb has complete info on the USART's, looks like something got dropped in the cut n paste!

 

Jim

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

The following code fails to hit the start frame interrupt ISR:

 

/*
* UARTSleepReceiveTransmit.ino
*
* Created: 7/18/2018 1:59:45 PM
* Author: Boompy
*/


#include <avr/interrupt.h>
#include <avr/sleep.h>

#define ENABLE_UART_START_FRAME_INTERRUPT UCSR0D = (0 << RXSIE) | (1 << SFDE)

volatile bool startFrameDetected = false;


ISR(USART0_START_vect){
	startFrameDetected = true;
}



ISR(USART1_START_vect){
	startFrameDetected = true;
}


uint8_t led_pin = 13;

void setup()
{

	/* add setup code here, setup code runs once when the processor starts */
	
	Serial.begin(9600);
	
	//Configure sleep mode for deep sleepage
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	//Enable UART start frame detection interrupt
	ENABLE_UART_START_FRAME_INTERRUPT;	
	
	//Set LED pin
	pinMode(led_pin, OUTPUT);
	//Turn off LED
	digitalWrite(led_pin, LOW);
	
	//Enable global interrupts
	sei();
}

unsigned long nextSleep = 0;
bool waitToSleep = false;

void loop()
{

	if(Serial.available()){
		while(Serial.available()){
			Serial.read();
		};
		Serial.println("YUP");
		nextSleep = millis() + 5000;
	}

	
	if(startFrameDetected){
		startFrameDetected = false;
		nextSleep = millis() + 5000;
		//Show that the ISR was invoked by turning on the on-board LED
		digitalWrite(led_pin, HIGH);
	}
	
	if(millis() > nextSleep){
		
		sleep_mode();
	}
	

}

 

I love the smell of burning silicon in the morning

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

jaza_tom wrote:
#define ENABLE_UART_START_FRAME_INTERRUPT UCSR0D = (0 << RXSIE) | (1 << SFDE)

 

needs to be:

 

#define ENABLE_UART_START_FRAME_INTERRUPT UCSR0D = (1 << RXSIE) | (1 << SFDE)

 

 

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

I wonder if you can use the Arduino IDE on an Mega328PB.......

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

I wonder if you can use the Arduino IDE on an Mega328PB.

Yes, if it is mounted to an M328PB X-Mini (and probably even if it's not) you can:

 

 

 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

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

I've also successfully used MiniCore in Arduino IDE with ATmega328PB as well

 

I love the smell of burning silicon in the morning

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

Reason I mentioned it is because the Arduino-ese usually has a bunch of stuff going on in this background that might be interfering with the ops code? Maybe, maybe not....

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Thu. Jul 19, 2018 - 10:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

jaza_tom wrote:
#define ENABLE_UART_START_FRAME_INTERRUPT UCSR0D = (0 << RXSIE) | (1 << SFDE)

 

needs to be:

 

#define ENABLE_UART_START_FRAME_INTERRUPT UCSR0D = (1 << RXSIE) | (1 << SFDE)

 

Woops, thanks for the correction.

 

Works like a charm now!

I love the smell of burning silicon in the morning

Last Edited: Thu. Jul 19, 2018 - 10:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please mark the solution!

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

Done

I love the smell of burning silicon in the morning