This is also applicable to the read or write of any of the Atmega MCU hardware control registers.

For example, here is a section of code below I needed to write to control TIMER 5 of an Atmega1280 chip on the Arduino MEGA board to output a 2500 Hz, 500 ns pulse on an I/O port bit. You will need to reference the chip data sheet in order to understand what the actual data does:

Your very welcome. I have seen this question come up here and there and though it was useful information. I have an example of a FIFO memory read routine I wrote and will post that as another example.

Sure beats reading in PORT bits one by one in a loop and assembling a byte in software (SLOW !!) when you can just read the FIFO a byte at a time and get on with processing the data.

Bill

In case it's not obvious to others, the direct port I/O is much faster than digitalWrite(). I had posted some scope screenshots in an Arduino forum on another site, but I forget the actual speed differences._________________Free Tibet. Release the Panchen Lama from prison. Let the Dalai Lama return to his home.

The bottom line here is that if digitalWrite() is "real time" enough and you dont care that the bits being manipulated are NOT time aligned, then use it. If speed is a requirment, then use direct port manipulation so long as the bit masking process involved, if required, while operating on single/multiple port bits does not bog your process down.

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum

Please support our site. If you click through and buy from our affiliate partners, we earn a small commission.