1

I am working on a project translating some Arduino code of a RFM Hopper Transmissor to C, but there are few concepts that I don't fully understand like the DDRB and DDRD.

For example, I call these two methods:

InputSDIO();
OutputSDIO();

which are declared in another file with these lines:

#define InputSDIO() (DDRB &= (~_SDIO))
#define OutputSDIO() (DDRB |= (_SDIO))

and it gives me the following error

error: expression is not assignable

Furthermore, I also get the same error from this call,

RX_ANTOut();

which is defined in another file with the following line:

#define RX_ANTOut() (DDRD |= (RX_ANT))

As I said, the code comes from an Arduino project of a transmissor. If you need any more info or if my question could be more detailed feel free to ask.

aep
  • 1,583
  • 10
  • 18
BarberaThor
  • 19
  • 1
  • 4

1 Answers1

2

In DDRB and DDRD the DDR is data direction register and it determines if a pin is an input or output (the uC is an Atmel AVR), DDRB is the DDR of port B, DDRD of port D. SDIO is a port configuration that is usually implemented as a bitmask. The operators &= and |= have the same meaning as +=, -=,... so i.e. a &= b means a = a & b and so DDRB &= (~SDIO) is equivalent to DDRB = DDRB & (~SDIO) what is a common way of bitmasking the ~ is logical negation & is logical AND, | is logical OR.

SDIO is an 8 bit (? what AVR model exactly is this ? ) binary number something like 0b01110010 that masks the pins of the port, i.e. port D

https://blog.podkalicki.com/bit-level-operations-bit-flags-and-bit-masks/, What is Bit Masking?

In the datasheet of the ATmega128RFA1 (https://cdn.sparkfun.com/datasheets/Dev/AVR/ATmega128RFA1_Datasheeta.pdf) the function of the DDRs is on page 191 in chapter 14.2.2 Configuring the Pin

ralf htp
  • 9,149
  • 4
  • 22
  • 34