The ports are PIO0_XX and PIO1_XX. The ports are 32 bits wide.
The users manual states: the VDD connection of the LPC845 Breakout board expansion connectors is an output from the board. The Board may only be powered via USB. The low drop out Torex regulator used on the board is capable of providing a total of 250mA, including on-board and off-board current. This will make embedding this in other electronics a little tricky. You would not want to drive voltage into the LPC845 I/O pins if it is unpowered. Likewise you would not want the LPC845 to drive voltage onto the I/O pins of the device that you are connected to. It would have been nice to be able to power this device from the expansion pins.
GPIO
Let start with the GPIO. We talking about on/off 1/0 input/output. I/O at its most basic. The GPIO ports are addressed as port0 and port1. The user guide to the LPC84X processor has a table which breaks down the GPIO memory space. The datasheet only calls out 0xA0000000, which is not as helpful.
From the datasheet: "GPIO registers are on the Arm Cortex-M0+ IO bus for fastest possible single-cycle I/O timing, allowing GPIO toggling with rates of up to 15 MHz."
GPIO speed using the libraries
Using the built in C language libraries we can toggle a GPIO pin. Yes the age old question, how fast can you toggle an GPIO pin? Using these 4 statements. I measured the GPIO output pin with a logic analyzer.
The GPIO pins toggles at 4.97uS or 402KHz. Not very fast. The logic analyzer is reporting twice what would normally be considered the frequency, so its more like 202.4Khz using the libraries.
Lets try direct C code access, like this:
uint32_t *MyGPIO = (uint32_t *)0xA0000008u; (...still using the standard libraries to configure the GPIO...) *MyGPIO = 0x00; *MyGPIO = 0x01; *MyGPIO = 0x00; *MyGPIO = 0x01;
The GPIO pin now toggles at 470ns or 4.2 MHz (2.13 MHz). About 10 times faster.
Looks like we need to try assembly language and see if we can get the speed up.
ARM Cortex M0 core registers
The General-purpose registers R0-R12 are 32-bit general-purpose registers for data operations. It uses the ARMv6-M Thumb® instruction set.
The processor implements the ARMv6-M Thumb instruction set, including a number of 32-bit instructions that use Thumb-2 technology. The ARMv6-M instruction set comprises: • All of the 16-bit Thumb instructions from ARMv7-M excluding CBZ, CBNZ and IT. • The 32-bit Thumb instructions BL, DMB, DSB, ISB, MRS and MSR.
To do our GPIO bit bang toggle test we going to need the Move and Store instructions. Probably should push and pop any registers that we need to use, as I am uncertain when using inline C assembly which registers C is using.
machine program is: str r1,[r0,#0]; str r2,[r0,#0]; with r1 = 0x0 and r2 = 0x1 and r0 = 0xA0000008;
Up to 130ns, 15.385 MHz (7.69 MHz). I don't understand why the signal is not closer to 50/50, as the same instruction is being used to change from a 0 to 1. No difference in timing when using the "str" vs "strb" instruction
Same machine code, but the second set of pulses now has a "nop" instruction between the "str" commands. Timing is now much closer to 50/50, but slower at 260ns 7.69MHz. This makes some sense as it says that a one clock instruction is taking 65ns 15 MHz. I need to figure out the default clock speed of this development board. Is it 15 MHz or 30 MHz?