if statement not picking up on variable change

Go To Last Post
124 posts / 0 new

Pages

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

FWIW I've just turned Jim's code into vanilla '328 code and it works as it should. Somewhere I have some 32E5s; I just need to find them.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

clawson wrote:
I have a rather strong distrust of debuggers myself based on a number of unpleasant experiences over the years so if I was backing anything here it would be that the debugger is lying about the 0x04 !

Or reads and clears the hardware register, making it 0 for the program when the if clause is evaluated.

With stm32 mcu's/debugger that can actually happen, and yes I have debugged for a "proplem" for day or two when it was just the debugger itself being the only proplem.

This is just a long shot, since i did notice anything about if you have tried running the program without debugging.

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

JoniS wrote:
Or reads and clears the hardware register, making it 0 for the program

Oh yes - there is that!

 

surprise

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

I would like to know what hardware is being used i.e. dongle,  RS232 cable, ...

and what Serial Terminal software is being used.

 

RS232 port on back of my Desktop PC. Direct cable to the Serial port of the STK600 and then to the XMEGA

 

Terminal software is Termite,  It sits quietly doing nothing until either it receves data, which it then displays, or it sends data if one types on the keyboard

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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

My wild guess is that you have 2 competing functions for the UDR, getchar AND the ISR.

 

As soon as the RX flag is set (getchar would be waiting for this) the ISR fires, gets the data from the UDR, clears the flag and getchar never sees the RX flag.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

But john, There is NOTHING else in the code other than that one line.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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


 

Somehow missed the fact that this was an Xmega project and we have a basic prioritised interrupt controller to deal with.

Also struggling to debug this because the ELF contains no debug information:

C:\Users\Nigel\Documents\Atmel Studio\7.0\jgmdesign>avr-readelf -a Debug\Exe\xmega_just_usart.elf

ELF Header:

  Magic:   7f 45 4c 46 01 01 01 03 00 00 00 00 00 00 00 00

  Class:                             ELF32

  Data:                              2's complement, little endian

  Version:                           1 (current)

  OS/ABI:                            UNIX - GNU

  ABI Version:                       0

  Type:                              EXEC (Executable file)

  Machine:                           Atmel AVR 8-bit microcontroller

  Version:                           0x1

  Entry point address:               0x0

  Start of program headers:          52 (bytes into file)

  Start of section headers:          116 (bytes into file)

  Flags:                             0x0

  Size of this header:               52 (bytes)

  Size of program headers:           32 (bytes)

  Number of program headers:         2

  Size of section headers:           40 (bytes)

  Number of section headers:         4

  Section header string table index: 1

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al

  [ 0]                   NULL            00000000 000000 000000 00      0   0  0

  [ 1] .shstrtab         STRTAB          00000000 000114 00001c 00      0   0  0

  [ 2] .text             PROGBITS        00000000 000130 00049c 00  AX  0   0  2

  [ 3] .signature        PROGBITS        00840000 0005cc 000003 00  WA  0   0  1

Key to Flags:

  W (write), A (alloc), X (execute), M (merge), S (strings)

  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)

  O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

Program Headers:

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align

  LOAD           0x000130 0x00000000 0x00000000 0x0049c 0x0049c R E 0x2

  LOAD           0x0005cc 0x00840000 0x00840000 0x00003 0x00003 RW  0x1

 Section to Segment mapping:

  Segment Sections...

   00     .text

   01     .signature

There is no dynamic section in this file.

There are no relocations in this file.

The decoding of unwind sections for machine type Atmel AVR 8-bit microcontroller is not currently supported.

No version information found in this file.

C:\Users\Nigel\Documents\Atmel Studio\7.0\jgmdesign>

Anyway using the simulator I get this:

 

 

The PC is stopped at the loop of interest but the USARTC0 appears to have interrupts disabled despite the comments in the (generated ?) code indicating that low-level was the intention.

 


{EDIT}

 

Oh that's just typical: A Refresh bug in  Atmel Studio 7 (Version: 7.0.2397 - )

The I/O registers don't get redrawn after {break} unless you close the fly-out then reopen the fly-out.

 

 

That's better.

I cannot be the only one who has been caught with this one.

 

Last Edited: Thu. Mar 12, 2020 - 09:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is NOTHING else in the code other than that one line.

But there are interrupts running in the background (clearing the RX flag??), that's what putting data into the receive buffer and increasing the rx counter.

 

See my screen shot here https://www.avrfreaks.net/commen...

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

jgmdesign wrote:

david.prentice wrote:

I would like to know what hardware is being used i.e. dongle,  RS232 cable, ...

and what Serial Terminal software is being used.

 

RS232 port on back of my Desktop PC. Direct cable to the Serial port of the STK600 and then to the XMEGA

 

Terminal software is Termite,  It sits quietly doing nothing until either it receves data, which it then displays, or it sends data if one types on the keyboard

 

JIm

That all looks pretty reliable.   I don't see where anything can go wrong.    After all,   people have been handling USARTs with interrupts since day one.    And using a similar method to check whether "data is available" in the receive buffer.

In fact CV has provided interrupt-driven Serial comms since CV was first released.    Even for a Tiny2313.

 

I often change "Mega" device in an AS7.0 project.    It is not so simple with E5, A1, A4, ... which have some subtle differences.

All the same,   you can set up the basics in a CodeWizard file.    And generate for E5, A1, A4, ...

 

I don't have any hardware E5.   But the E5 appears to be a cut-down Xmega.    32E5 is the biggest in the family.

If there was a 128E5 it would be worth playing with.

 

David.

Last Edited: Thu. Mar 12, 2020 - 09:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

There is NOTHING else in the code other than that one line.

But there are interrupts running in the background (clearing the RX flag??), that's what putting data into the receive buffer and increasing the rx counter.

 

See my screen shot here https://www.avrfreaks.net/comment/2868156#comment-2868156

The counter only increments when i type something into the terminal. I can see if there is a flag set just before the sei, but the puts works and thats after the sei.

Groan. I may email Pavel and take my chances.
Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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



The counter only increments when i type something into the terminal.

Correct and the interrupts handle that as well as putting the data into the RX buffer.

 

The program just gets stuck in an endless loop at 0x00C5.

 

 

 

 

so there is something wrong with the line if (DATARECEIVED()) putchar(getchar()); or the way it is constructed

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:

...

The program just gets stuck in an endless loop at 0x00C5.

...

so there is something wrong with the line if (DATARECEIVED()) putchar(getchar()); or the way it is constructed

 

 

See #11.  That loop is the catch loop, for when you run off the end of main(). Now, how does one get there?

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

OK this HAS BEEN fun but it is interfering with piano practice and learn to read music. devil I have spent on this all the neurons I could afford.

 

Looking at the disassembly view this is what's happening:

 

1) The string is printed OK.

 

2) The code at the non working line keeps on looking for the counter to be above zero, this runs as long as nothing is typed into the terminal.

 

3) As soon as a char is typed in and the counter goes to 1 then the code seems to be getting the char and printing it??, the RX counter goes back to zero and then, SOMEHOW, the code goes to the endless loop at C5.

 

4) Any further chars typed in will increment the counter and the data gets stored into the RX buffer by the ISR but nothing else happens as the code is stuck in the endless loop.

 

and as porky pig would say tha..tha...that's all folks.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:
then, SOMEHOW, the code goes to the endless loop at C5.

Doesn't this smell like an uncaught interrupt? 

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

I see Lee is having his fun......

 

Update:

 

Ok, I have made some progress.

 

If I Stick with the original:

while (1)
      {
         if (DATARECEIVED()) putchar(getchar());  //This does nothing.  No output

      }
}

The program goes to that loop and stays there.

 

But if I do this:

while (1)
      {
         if (DATARECEIVED()) putchar(getchar());  //This does nothing.  No output
		else
		{
			#asm("nop")
		}
			
	  }
}

It WORKS!! I can enter text on the terminal and it is echoed back

 

Or if I set a bit on PORTA:

while (1)
      {
         if (DATARECEIVED()) putchar(getchar());  //This does nothing.  No output
		
		PORTA.OUTSET = PIN5_bm;
	  }
}

This also works.  I can enter text on the terminal and it is echoed back

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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

Well there you go! You are not just a pretty face. cheeky

 

Thanks for proving my theory wrong too, I can confirm your findings. The counter must get reset to zero every time a new char comes in and gets printed out but the data is still going into the RX circular buffer.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:

Well there you go! You are not just a pretty face. cheeky

 

Thanks for proving my theory wrong too, I can confirm your findings. The counter must get reset to zero every time a new char comes in and gets printed out but the data is still going into the RX circular buffer.

 

Yabbut I am still scratching my head as to WHY just having:

while (1)
      {
         if (DATARECEIVED()) putchar(getchar());  //This does nothing.  No output

      }
}

Is causing such a fuss.  If it were a C issue I would think the compiler would spit up a fuss.  Then again......

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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

js wrote:
The counter must get reset to zero every time a new char comes in and gets printed out but the data is still going into the RX circular buffer.

 

Not exactly.

 

If I wasn't constantly polling the counter, then it would increment by one every time a character came in.  Then once I did poll the counter and see that it no longer was zero I would have to run a routine to read out the buffer and clear the counter(through GETCHAR() )

 

And make sure I poll and readout before the counter resets and the buffer is over written.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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

jgmdesign wrote:

It WORKS!! I can enter text on the terminal and it is echoed back

 

This really doesn't make sense.

 

This...

    while (1)
    {
        if (DATARECEIVED()) putchar(getchar());  //This does nothing.  No output

    }

...generates this code...

                 ; 0000 0061     while (1)
                 _0x3:
                 ; 0000 0062     {
                 ; 0000 0063         if (DATARECEIVED()) putchar(getchar());  //This does nothing.  No output
000097 91e0 240a 	LDS  R30,_rx_counter_usartc0
000099 30e0      	CPI  R30,0
00009a f019      	BREQ _0x6
00009b d10a      	RCALL _getchar
00009c 2fae      	MOV  R26,R30
00009d d14e      	RCALL _putchar
                 ; 0000 0064 
                 ; 0000 0065     }
                 _0x6:
00009e cff8      	RJMP _0x3
                 ; 0000 0066 
                 ; 0000 0067 }
                 _0x7:
00009f cfff      	RJMP _0x7

 

Which is exactly what you'd expect.

 

Whereas this...

    while (1)
    {
        if (DATARECEIVED()) putchar(getchar());  //This does nothing.  No output
        else
        {
            #asm("nop")
        }
			
    }

...generates this...

                 ; 0000 0061     while (1)
                 _0x3:
                 ; 0000 0062     {
                 ; 0000 0063         if (DATARECEIVED()) putchar(getchar());  //This does nothing.  No output
000097 91e0 240a 	LDS  R30,_rx_counter_usartc0
000099 30e0      	CPI  R30,0
00009a f021      	BREQ _0x6
00009b d10c      	RCALL _getchar
00009c 2fae      	MOV  R26,R30
00009d d150      	RCALL _putchar
                 ; 0000 0064 		else
00009e c001      	RJMP _0x7
                 _0x6:
                 ; 0000 0065 		{
                 ; 0000 0066 			#asm("nop")
00009f 0000      	NOP
                 ; 0000 0067 		}
                 _0x7:
                 ; 0000 0068 
                 ; 0000 0069     }
0000a0 cff6      	RJMP _0x3
                 ; 0000 006A 
                 ; 0000 006B }
                 _0x8:
0000a1 cfff      	RJMP _0x8

 

Which is also what you'd expect.

 

We know the code works on a '328 because I've run it.

 

That leaves either some odd behaviour of the chip itself, something about the debug environment, or a hardware issue.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

It works fine on an A4U.   I can't see any reason for an E5 to behave differently.   Either the Compiler or the E5 chip.

 

I don't have an E5.   Can anyone (other than Jim) confirm E5 behaviour?

 

From a debugger point of view.   Move statements to separate lines.    Easier to identify / set Breakpoints.

It makes no difference to the generated code.

 

If the low pin count E5 had a 128k or 256k family member,   I would buy a board (or even a bare chip).

If someone can confirm the E5 misbehaviour,  I will buy the E5 XPLD board to satisfy my scepticism.

 

David.

Last Edited: Fri. Mar 13, 2020 - 08:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

It works fine on an A4U.   I can't see any reason for an E5 to behave differently.   Either the Compiler or the E5 chip.

 

Was that using Jim's posted code?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

Yes.   Generate from CodeWizard file.   (change device from 32E5 to 128A4U)

 

Do you own an E5 ?

 

It is Friday.   So Farnell would not deliver an XPLD until Monday.    I don't want to mess around with a bare chip.

 

David.

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


david.prentice wrote:

Do you own an E5 ?

 

Found my 32E5 breakout boards. A bit of a lash-up...

 

 

 

BUT...I can confirm Jim's findings.

 

This...

    while (1)
    {
        if (DATARECEIVED()) putchar(getchar());
    }

 

...does not work. Whereas this...

 

    while (1)
    {
        if (DATARECEIVED()) {
            putchar(getchar());
        } else {
            #asm("nop");
        }
    }

...does.

 

Very odd.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

For completeness I changed the first bit of code to this...

 

    while (1)
    {
        if (DATARECEIVED()) {
            putchar(getchar());
        } else {
//            #asm("nop");
        }
    }

...with the same result.

 

 

Generated code for the non-working version...

 

                 _0x4:
                 ; 0000 0062     {
                 ; 0000 0063         if (DATARECEIVED()) {
0000b1 91e0 2419 	LDS  R30,_rx_counter_usartc0
0000b3 30e0      	CPI  R30,0
0000b4 f019      	BREQ _0x7
                 ; 0000 0064             putchar(getchar());
0000b5 d10a      	RCALL _getchar
0000b6 2fae      	MOV  R26,R30
0000b7 d14e      	RCALL _putchar
                 ; 0000 0065         } else {
                 _0x7:
                 ; 0000 0066 //            #asm("nop");
                 ; 0000 0067         }
                 ; 0000 0068     }
0000b8 cff8      	RJMP _0x4
                 ; 0000 0069 
                 ; 0000 006A }
                 _0x9:
0000b9 cfff      	RJMP _0x9

 

And the working version...

 

                 _0x4:
                 ; 0000 0062     {
                 ; 0000 0063         if (DATARECEIVED()) {
0000b1 91e0 2419 	LDS  R30,_rx_counter_usartc0
0000b3 30e0      	CPI  R30,0
0000b4 f021      	BREQ _0x7
                 ; 0000 0064             putchar(getchar());
0000b5 d10c      	RCALL _getchar
0000b6 2fae      	MOV  R26,R30
0000b7 d150      	RCALL _putchar
                 ; 0000 0065         } else {
0000b8 c001      	RJMP _0x8
                 _0x7:
                 ; 0000 0066             #asm("nop");
0000b9 0000      	NOP
                 ; 0000 0067         }
                 _0x8:
                 ; 0000 0068     }
0000ba cff6      	RJMP _0x4

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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


OK, this gets weirder.

 

I've just run both ASM files through a Diff and the only differences are those in the generated code above.

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

Last Edited: Fri. Mar 13, 2020 - 10:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Things that don't seem to make any difference....

 

1) Running TX and RX on different interrupt priority levels

2) Running on the same level but with Round Robin scheduling turned on

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

Have to come back to this later - it's Friday so it must be paperwork day.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

Brian Fairchild wrote:
it's Friday so it must be paperwork day.
I've never heard beer described in that way!

 

As to the issue here. I wonder if there's anyone who has both "traditional Xmega" and "E5" to compare behaviour on the two ?

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

Is there some atomic protection that might be starved by the interrupts? The inclusion of a nop() would support that methinks.

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

I get exactly the same as you.   (as I would expect)

                 _0x4:
                 ; 0000 0057     {
                 ; 0000 0058         if (DATARECEIVED()) {
000163 91e0 2813 	LDS  R30,_rx_counter_usartc0
000165 30e0      	CPI  R30,0
000166 f019      	BREQ _0x7
                 ; 0000 0059             putchar(getchar());  //works fine on A4U
000167 d11d      	RCALL _getchar
000168 2fae      	MOV  R26,R30
000169 d161      	RCALL _putchar
                 ; 0000 005A         } else {
                 _0x7:
                 ; 0000 005B //            #asm("nop");
                 ; 0000 005C         }
                 ; 0000 005D     }
00016a cff8      	RJMP _0x4
                 ; 0000 005E }
                 _0x9:
00016b cfff      	RJMP _0x9

But my program works fine on the 128A4U target with or without the NOP.

 

I have far too many "evaluation boards".   Hey-ho.   My Farnell order for ATXMEGAE5-XPLD has just been placed.

 

David.

Last Edited: Fri. Mar 13, 2020 - 10:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
it's Friday so it must be paperwork day

That's not a euphemism for panic-buying toilet roll, is it ... ?

 

cheeky

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A guess (I don't have the HW so I can't check).

 

perhaps 

DATARECEIVED()

stops putchar from working, and the NOP (any delay) makes it work.

 

A way to test is to change baudrate. With the NOP a slower TX will also fail, and with faster the org. code will work. 

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

theusch wrote:
Doesn't this smell like an uncaught interrupt? 

Sorry; uncaught interrupt by default would jump to zero.

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

Interesting findings.

I am not at my development PC today, but if someo e wants to try out a thought i had.....

Throw some code BEFORE the IF statement and remove the stuff after the IF and see what happens.

Another test is to add code before the IF statement, remove the else/NOP, and add some code to do something after the IF.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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

Look at the serial code - how is it doing the atomic protection?

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

Not working...

 

    while (1)
    {
        if (DATARECEIVED()) {
            #asm("nop");
             n =getchar();
             putchar(n);
        } else {
//            #asm("nop");
        }
    }

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

OK, there's something odd going on as you switch between different optimisation levels.

 

Low and Speed optimisation works without the NOP, the other speed optimisations don't.

 

Ditto for the three size optimisations.

 

This is a vanilla file straight from the wizard with just the obvious additions at the bottom of main.

 

 

Attachment(s): 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

Jim...

 

what happens if you turn the optimisation down to LOW?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

>This is a vanilla file

 

Probably doesn't do much good without the lst file, as some do not have cv to compile with.

 

 

 

Put the nop as the first thing in the while loop, so every read via lds r30 is preceded by the nop. Doesn't seem like the lds r30 likes the back to back reads when no other memory access takes place between reads (lds r30, cpi r30, rjmp, rjmp). The nop does something, and you would think an interrupt that will take place would also 'correct' the problem (but maybe see below).

 

You could also try to get the buffer count read to use a pointer so the resulting code is not using lds r30, just to see what a different type of access acts like.

 

This is the end of the isr (from the jgm listing in the zip file, anyway)-

 

000200 91e9          LD   R30,Y+
000201 bfef          OUT  SREG,R30
000202 91f9          LD   R31,Y+
000203 91e9          LD   R30,Y+
000204 91a9          LD   R26,Y+
000205 9518          RETI

 

Maybe the the pointer register usage has something to do with it, as the isr leaves with its last memory access as a pointer type access. In the avr0/1, I saw a strange problem where writing to the sleep control register would not work when using a pointer register to access (compiler generated code used pointers for some reason, then the problem showed up), but either adding a nop or getting the compiler to produce lds/sts (normal), or splitting up the write into two ops 'fixed' the problem. Maybe there are combinations of x/y/z pointer use that create a problem, although if so it must be a rare combo or you would think it would be causing problems all over the place.

 

I'm not sure what can be done in cv, but if a nop could be inserted before the reti, that could also maybe reveal something useful. Maybe.

 

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

OK, this is it from me for a day or so.

 

This works with Speed, Low optimisation...

 

    while (1)
    {
        if (rx_counter_usartc0 != 0) {
            putchar(getchar());
//        } else {
//            #asm("nop");
        }
    }

As does this...

 

    while (1)
    {
        if (rx_counter_usartc0 != 0) {
            putchar(getchar());
        } else {
            #asm("nop");
        }
    }

 

This does not work with Speed, Maximal...

 

    while (1)
    {
        if (rx_counter_usartc0 != 0) {
            putchar(getchar());
//        } else {
//            #asm("nop");
        }
    }

 

Whereas this does...

 

    while (1)
    {
        if (rx_counter_usartc0 != 0) {
            putchar(getchar());
        } else {
            #asm("nop");
        }
    }

 

[this is as much about reminding me where I got to as anything else]

 

[That said I am very confused and may be going down the wrong rabbit hole]

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

curtvm wrote:

Put the nop as the first thing in the while loop, so every read via lds r30 is preceded by the nop.

 

Like this?

 

    while (1)
    {
        #asm("nop");
        #asm("nop");
        #asm("nop");
        #asm("nop");
                    
        if (rx_counter_usartc0 != 0) {

            putchar(getchar());
//        } else {
//            #asm("nop");
        }
    }

Doesn't work.

 

The .lst file for this version (not working)...

 

    while (1)
    {
        if (rx_counter_usartc0 != 0) {
            putchar(getchar());
//        } else {
//            #asm("nop");
        }
    }

 

...is attached.

Attachment(s): 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "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."

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

Can anyone (other than Jim) confirm E5 behaviour?

Don't people read replies?  wink I was the first to confirm the beahviour in #67.

My Farnell order for ATXMEGAE5-XPLD has just been placed.

I was going to offer you the Xplained board I got from Atmel even before the E5 was released. This of course goes against my hoarder instinct....

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:
I was going to offer you the Xplained board I got from Atmel even before the E5 was released.

The situation appears widespread (at least two have recreated?), but is it time to gather the date code/chip rev of the various setups?

 

In that vein, I was going to peek at errata.  Anyone have a hint to find the errata?  The datasheet just says "go to microchip.com".  And I saw no link in a pass at the product page.

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: Fri. Mar 13, 2020 - 09:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jesus guys, been following this post.  Has anyone figured the problem yet?  Strange!

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

The Xmega32E5 target is a barrier to many (including me).

 

I had a thought about using the simulator though. Has anyone been successful using the Atmel stimulus file (.stim) to inject characters into the simulator's USART ? (Documentation on .stim files is sparse)

 

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

The Xmega32E5 target is a barrier to many

Why? It's just a nice little chip. I have about 3,000 boards in the field with the E5.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:

The Xmega32E5 target is a barrier to many

Why? It's just a nice little chip. I have about 3,000 boards in the field with the E5.

 

I have to agree.  It is a nice chip.

 

 

Back to topic,

I have a huge non-avr project I need to get on.  And I also need to start/finish the one with the XMEGA in so I am going to get back to writing the application and watching the behaviour of things.  I will email Pavel at some point and see if he has an explanation as to why things are happening.  We shall see what the Big PoohBahh has to say.

 

Stay tuned Kiddies!

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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

One more thing to add.

 

I just fired up the program we have been dissecting and I deleted everything from teh WHIE() loop and hit RUN debugger.  The code sits in the while loop and does not go to the WHILE loop in getchar().

 

Very interesting why either the MACRO, or writing the line of code itself in the while loop causes the problem...

 

All for now

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

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

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

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

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

N.Winterbottom wrote:

The Xmega32E5 target is a barrier to many (including me).

What I meant by that is, because not many freaks can immediately lay their hands on some real silicon; that it's a barrier to solving the weird problem.

 

Hence my sub-question about injecting characters into the Atmel Simulator.

 

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

My 32E5-XPRO will arrive tomorrow.

 

It should be fairly simple to see whether the 32E5 silicon behaves differently to 32A4U silicon.   Or even mega4809, tiny817, ... silicon.

Or whether Codevision does something different for 32E5.

 

I am intrigued.   The 32E5 has been available for about 5 years.  XmegaA1 was released in 2007.   The Xmega, mega-0, tiny-0, tiny-1 have been available for several years.    There is nothing "new" but of course silicon is revised,  compilers are updated, ...

 

David.

Pages