Noobie Data Sheet Symbol Question -- meaning of Curly brackets in data sheet

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

I am reading over the data sheet for the attiny85.  On page 54, the following statement appears:

 

When switching between tri-state ({DDxn, PORTxn} = 0b00) and output high ({DDxn, PORTxn} = 0b11), an inter-
mediate state with either pull-up enabled {DDxn, PORTxn} = 0b01) or out put low ({DDxn, PORTxn} = 0b10) must
occur.

what do the curly braces (as in "{DDxn, PORTxn} = 0b00") denote?

 

 

EDIT:  I edited the post title to be more descriptive -- to help others that might have a similar question in the future

This topic has a solution.

Russ

Last Edited: Wed. Jan 12, 2022 - 02:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


The x and n are to be replaced by actual port and pin numbers. So a specific example might be x=B and n=5 giving you:

 

DDRB = (1 << 5);

PORTB = (1 << 5);

 

That would set the two bits (one in DDR and one in PORT) to the 0b11 combination which means "output high".

 

Bottom line is that when setting DDRx you set bits in that to be 0 for any bits that need to be input and set 1 for any that are output. So for example:

 

DDRB = 0b00000101

 

would set just bits 0 and 2 to be output and the rest would be input (by default the whole DDRB holds 0x00 soo all pins are input by default).

 

For the paired bits in DDR and PORT you have the potential combinations:

DDR PORT
0   0   = input
0   1   = input with pullup
1   0   = output low
1   1   = output high

That is basically what they are trying to say in that paragraph but, as you can see, it's hopefully much clearer if you write it out as a table.

 

EDIT: the datasheet reminds me:

 

 

That tiny85 only has a port B so for this chip 'x' is always going to be 'B' and it only has bits 0, 1, 2, 3, 4, (5) so 'n' is only going to be 0..5 (actually 0..4 in reality as you would be very unwise to try using PB5 as it involves RSTDISBL).

Last Edited: Wed. Jan 12, 2022 - 11:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


gatoruss wrote:
what do the curly braces (as in "{DDxn, PORTxn} = 0b00") denote?

As clawson said, the x and n denote the specific port (x) and the bit within that port (n).

 

This is because each bit can be different; you're not restricted to just setting all the pins in the port to the same configurations - some can be inputs, some can be outputs, some can have pullups enabled.

 

The curly braces indicate that it's a combination of the bits in the two registers:

{DDxn, PORTxn} = 0b00 - ie, DDxn0 and PORTxn0

{DDxn, PORTxn} = 0b11 - ie, DDxn1 and PORTxn1

{DDxn, PORTxn} = 0b01 - ie, DDxn0 and PORTxn1

{DDxn, PORTxn} = 0b10 - ie, DDxn1 and PORTxn0

 

It would probably be clearer if they'd have presented it as a table

 

See the earlier section in the datasheet, which explains these combinations of DDR and PORT register settings:

 

https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf

 

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

Thank you for the quick reply.  I am having trouble processing the following statement. 

 

clawson wrote:
That would set the two bits (one in DDR and one in PORT) to the 0b11 combination which means "output high".

 

I had thought that the DDRx and PORTx were separate registers, each representing a separate byte -- how can they be combined with a result of 0b11?

 

I am sorry to be obtuse.

Russ

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

gatoruss wrote:
I had thought that the DDRx and PORTx were separate registers, each representing a separate byte

Yes - that is correct.

 

how can they be combined with a result of 0b11?

See the datasheet section I linked - it's the combined effect of setting the two separate bits.

 

As we both said, it would have been a lot better presented as a table.

 

EDIT

 

Or, perhaps, if they'd written:

When switching between tri-state (DDxn=0 and PORTxn=0) and output high (DDxn=1 and PORTxn=1), an intermediate state with either pull-up enabled (DDxn=0 and PORTxn=1) or output low (DDxn=1 and PORTxn=0) must occur...

The curly brace stuff does rather seem like someone trying to be cute - when it's no easier that just writing it in plain English

 

frown

 

And they did get the parentheses wrong on the 01 case 

 

EDIT 2

didn't quite get Edit 1 complete

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: Wed. Jan 12, 2022 - 12:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your patience.

 

Given clawson's example (i.e., x= 5), it is my understanding that setting bit 5 in the DDRx register and setting bit 5 in the PORTx register results in the following:

 

DDRx = 0b00010000

 

and

 

PORTx = 0b00010000

If you AND 0b00010000 & 0b00010000, you get 0b00010000, correct?

 

I am getting lost on how setting bit 5 on both DDRx and PORTx equals 0b11 -- which is the same as 0b00000011, correct?

Russ

Last Edited: Wed. Jan 12, 2022 - 01:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

The curly brace stuff does rather seem like someone trying to be cute - when it's no easier that just writing it in plain English

 

frown

 

And they did get the parentheses wrong on the 01 case 

 

And here I was thinking that the curly braces denoted some complex operation on binary numbers and I was so focused on those brackets that I didn't see the missing parenthesis! blush

Russ

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gatoruss wrote:
how can they be combined with a result of 0b11?

OK consider this:

DDRB  = 0b1100;
PORTB = 0b1010;

(I'm only setting bits to affect bits 0..3 for the purpose of illustration and non-duplication!). So you have to take the contents of these two register together.

 

Look first at the very right most bits - that is bit 0 of DDRB and bit 0 or PORTB.  Both are 0 so combined you could say that for this particular bit (pin 0) the combination is 0b00. So in:

DDR PORT
0   0   = input
0   1   = input with pullup
1   0   = output low
1   1   = output high

it's the combination I have highlighted for pin B0 - the pin is input but with no pull up. Move one place to the left and you then have DDR bit1 is 0 and PORT bit 1 is 1. So this is 0b01. That is:

DDR PORT
0   0   = input
0   1   = input with pullup
1   0   = output low
1   1   = output high

So I have set pin 1 to be an input but with the pull-up resistor enabled.

 

Moving left again then for bit 2 in DDR I have a 1 bit and for PORT at bit/pin2 I have a 0 bit so this time it is (0b10):

DDR PORT
0   0   = input
0   1   = input with pullup
1   0   = output low
1   1   = output high

and finally in the top of my 4 bits written to each register I have the bit for pin 3 in DDR set to 1 and the bit for pin 3 in PORT set to 1 so it's 0b11 and that means pin 3 (PB3) is:

DDR PORT
0   0   = input
0   1   = input with pullup
1   0   = output low
1   1   = output high

Or to turn this around the other way, say you want to set PB2 to be an output and drive it low what would you do? You need the 0b10 combination which would mean:

DDRB  |=  (1 << 2);
PORTB &= ~(1 << 2);

(I know what your next question is going to be: |= means "set the given bit but leave the others untouched" and &= ~(bit pattern) means "clear the given bit but leave the others untouched - if still not clear read "Bit Manipulation 101" in the Tutorial Forum).

Last Edited: Wed. Jan 12, 2022 - 01:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, again.

 

clawson wrote:
Both are 0 so combined you could say that for this particular bit (pin 0) the combination is 0b00.

 

So, the "0b00" is not the result of an operation, but is instead shorthand for "...neither bit n of DDRx nor bit n of PORTx are set."  Am I getting close?

 

clawson wrote:
(I know what your next question is going to be: |= means "set the given bit but leave the others untouched" and &= ~(bit pattern) means "clear the given bit but leave the others untouched - if still not clear read "Bit Manipulation 101" in the Tutorial Forum).

 

I have read that tutorial (a few times )smiley and have been googling and reading up on bit manipulation -- especially recently in trying to find out what those curly brackets mean.  That said, I will go back and read the tutorial again.

 

Thanks again.

Russ

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

gatoruss wrote:
So, the "0b00" is not the result of an operation, but is instead shorthand for "...neither bit n of DDRx nor bit n of PORTx are set."  Am I getting close?

You got it!!!!

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

If you want something you've never had...

...you must be willing to do something you've never done!

Lets go Brandon!

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

Thanks to all.  I am appreciative of your time and patience.

 

Have a great day!

Russ

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

It's sort-of mathematical set notation.  "{PB5, DDB5} = 0b00" means "the set of config register bits PB5 and DDB5 are both 0"
I guess it would be nice if they had the "types" on both sides of the = be the same: "{PB5, DDB5} = {0,0}", but...

 

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

westfw wrote:
It's sort-of mathematical set notation.

 

It does seem so.  Before my initial post, I had done some cursory reading up on set operations, etc. 

 

westfw wrote:
I guess it would be nice if they had the "types" on both sides of the = be the same: "{PB5, DDB5} = {0,0}"

 

Indeed.

Russ