How to access the serial pins?

I’ve puzzled through the basics and have a basic grip on the Blinks dev now. I have the serial monitor working properly, which is great. But I’ve seen references to using the serial pins as more general input/output pins. How do you access these at a hardware layer? I can access the port and send noise by printing through ServicePortSerial, but I don’t see a pinMode() or digitalWrite() equivalent to get me to the pin level. Thanks.

“Use the source, Luke” :slight_smile:

hmmm… that’s what I’ve been doing! But writing bytes to the serial port is not the same as being able to turn pins on or off…

I would assume, although I did not look at it, that if you check sp.h and associated files you should find what you need. What I pointed you to is just a possible entry point to help you figuring it out. You will have to dig deeper.

Here are the #defines for the service port pins…

/*** SERVICE PORT ***/


// Service port hardware

// Pins as digital IO

#define SP_A_PORT PORTE
#define SP_A_PIN  PINE
#define SP_A_DDR  DDRE
#define SP_A_BIT  2

#define SP_R_PORT PORTD
#define SP_R_PIN  PIND
#define SP_R_DDR  DDRD
#define SP_R_BIT  0

#define SP_T_PORT PORTD
#define SP_T_DDR  DDRD
#define SP_T_BIT  1

You can paste the above lines into the top of your sketch, or make a header file (like blinkio.h) and #include that at the top of your program.

Then to enable the R pin for output, you would use (probably in setup())…

SP_R_DDR |= _BV( SP_R_BIT );

…and then to make the R pin go high, you would…

SP_R_PORT  |= _BV( SP_R_BIT );

…and to make it go low…

SP_R_PORT &= ~_BV( SP_R_BIT );

The above lines are examples of Arduino direct port manipulation using registers (as opposed to pinMode() and digitalOut()). There used to be a page in the Arduino reference documentation about how this works, but they seem to have removed it? See if you can google it, and if not LMK and I’ll try to find an explanation.

Notes:

  1. Each one of these lines compiles down to a single instruction that executes in a single cycle, so they are very fast.
  2. If you enable the serial port then none of the above lines will work because those pins will be switched into serial port mode.
  3. Some blinks do not physically have an A pin.

I am away from my blinks computer so am typing the above from memory and can not test, so do not hesitate to report back if you are having any problems!

Here is an OK explanation of how/why direct port manipulation works…

Note that _BV() is defined as…

_BV( bit ) ( 1<<(bit) )