Confused: pinA is read only but I can copy data to it!

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

Hi,

using AVR studio for Atmega8515. According to the datasheet, pinX is read only; however, when I write

out pina, r16, I noticed that r16 is copied into pina.

I for instance, set DDRA to 0x50, and r16 to 0xFF, yet the simulator shows that pina=0xff despite that not all pins were to set to one. Any explanation?

How this code behaves in real hardware?

 

Thank you

Last Edited: Wed. Sep 16, 2020 - 11:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An99gy wrote:
out pina, r16, I noticed that r16 is copied into pina.
Noticed in what? Simulator or the real chip?

 

The fact is that in later AVR you could write to PINx (it has the affect of toggling bits in PORTx when you do) but the 8515 predates that. However I could well believe that the sim uses a common simulation so it may accept the write even if, in the real silicon, it has no actual effect.

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

In your previous thread, clawson wrote:
the 8515 is such an old model of AVR ... I wonder why you are using 8515 in 2020?

 

https://www.avrfreaks.net/commen...

I also wondered that!

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

Hi dawson,

Thank you for your answer.

My remark was about the Simulator output as I don't have a hardware kit yet.

Thank you

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

If the question is resolved, please mark the solution - see other thread.

 

An99gy wrote:
dawson

laugh

 

Note that it's "CLAWSON": the first two letters are 'c' and 'l' - not 'd'

 

 

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

Sorry CLawson blush

Here is the code I tried

.include "m8515def.inc"

.equ val1= 0xff
.equ val2= 0x50
.equ val3= 0x44
ldi r16, val1
ldi r17,val2
ldi r18,val3
sts ddra+0x20,r17
out porta,r16
out pina, r18

nop

 

I ended up with DDRA= 0x50, pinA=0x44, porta=0xFF

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

You learned your first lesson of programming today:

 

"don't trust simulators"

 

(this is actually pretty ironic as my day job is writing simulators!! (Having said that, that puts me in a good place to know how reliable/unreliable they can be!))

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

An99gy wrote:
I for instance, set DDRA to 0x50, and r16 to 0xFF, yet the simulator shows that pina=0xff despite that not all pins were to set to one. Any explanation?

Sure,

 

When you have a PIN set as an INPUT, and you write a '1' to the PORT pin that is configured as an INPUT, a PULLUP is enabled and as such the PINAx bit will read as one unless a stimulus is holding the pin low.

 

 

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

Practically: at least on an AVR, you can write even to read-only registers. That action SHOULD have no effect. But, who knows whether a simulator will honor that.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

As a bit of a tangent, it's important to remember that peripheral registers (sometimes called "Special Function Registers", "SFRs") are not (just) memory - they are control signals to the hardware.

 

An important consequence of this is that it is often not the case that what you write to an SFR can be read-back from that SFR.

 

PINx has already been cited as an example: Reading it gives you the states of the inputs, but writing it (on some models) will toggle an output.

 

Another common example (not just on AVRs) is the UART data register: Writing to it loads data to be transmitted, but reading it retrieves received data.

 

#SfrNotMemory

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...
Last Edited: Mon. Oct 5, 2020 - 09:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Also, writing 1 to some interrupt flag registers will RESET the interrupt flag bit (e.g. make it 0). So, for those, the bit becomes the opposite of what you write!

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Ah yes - some processors have Set/Clear/Toggle registers for IO ports: when you write a 1 to a bit in those, they will Set, Clear, or Toggle the "target" bit

 

There was a discussion about it recently:

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

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...
Last Edited: Thu. Sep 17, 2020 - 05:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
Note that it's "CLAWSON"

Son of Claw

zbaird wrote:
Although it is rumored that I sometimes poke a little fun at the Son of Claw, I'd like to say that I really appreciate his dedication, wisdom, even temperment, and wonderful contributions to this site.

https://www.avrfreaks.net/forum/...

 

zbaird wrote:
King Samperi couldn't take it. He dropped the book without ceremony. No Usch, no Son of Claw, no thrilling adventures. Just weirdo geek crap with a pseudo science fiction twist. "Spirits - bah, humbug!" thought the King to himself, then a small smile crept across his face. "How seasonal I am," he thought, "A regular Scrooge."

https://www.avrfreaks.net/commen...

 

[edit]  You veteran 'Freaks -- just spent an enjoyable time revisiting the exploits of Son of Claw and The Usch and King Samperi and etc.  See the hits with

https://lmgtfy.app/?q=site%3Awww...

 

 

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. Sep 17, 2020 - 07:56 PM