Hi.
While trying to blink the led with this program:
#include "Arduino.h"
void setup()
{
pinMode(13,OUTPUT);
//REG_PIOB_OWER=g_APinDescription[13].ulPin;
}
void loop()
{
portOutputRegister(digitalPinToPort(13)) = 0xffffffff & g_APinDescription[13].ulPin;
delay(1000);
portOutputRegister(digitalPinToPort(13)) = 0x0 & g_APinDescription[13].ulPin;
delay(1000);
}
I've found two problems.
The first one, it wouldn't compile unless I would change the sintaxe in Arduino.h in lines 56 and 57.
After replacing this:
#define digitalPinToPort(P) ( g_APinDescription[P]->pPort )
#define digitalPinToBitMask(P) ( g_APinDescription[P]->ulPin )
with this:
#define digitalPinToPort(P) ( g_APinDescription[P].pPort )
#define digitalPinToBitMask(P) ( g_APinDescription[P].ulPin )
It compiled without errors.
But even after this, the led wouldn't blink.
I've found that after enabling the OWER register int setup it works.
To avoid setting pinMode and also OWER, I've added this to wiring_digital.c in pinMode function for case OUTPUT:
g_APinDescription[ulPin].pPort -> PIO_OWER = g_APinDescription[ulPin].ulPin;
The functions ends up like this:
extern void pinMode( uint32_t ulPin, uint32_t ulMode )
{
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
{
return ;
}
switch ( ulMode )
{
case INPUT:
/* Enable peripheral for clocking input */
pmc_enable_periph_clk( g_APinDescription[ulPin].ulPeripheralId ) ;
PIO_Configure(
g_APinDescription[ulPin].pPort,
PIO_INPUT,
g_APinDescription[ulPin].ulPin,
0 ) ;
break ;
case INPUT_PULLUP:
/* Enable peripheral for clocking input */
pmc_enable_periph_clk( g_APinDescription[ulPin].ulPeripheralId ) ;
PIO_Configure(
g_APinDescription[ulPin].pPort,
PIO_INPUT,
g_APinDescription[ulPin].ulPin,
PIO_PULLUP ) ;
break ;
case OUTPUT:
PIO_Configure(
g_APinDescription[ulPin].pPort,
PIO_OUTPUT_1,
g_APinDescription[ulPin].ulPin,
g_APinDescription[ulPin].ulPinConfiguration ) ;
g_APinDescription[ulPin].pPort -> PIO_OWER = g_APinDescription[ulPin].ulPin;
/* if all pins are output, disable PIO Controller clocking, reduce power consumption */
if ( g_APinDescription[ulPin].pPort->PIO_OSR == 0xffffffff )
{
pmc_disable_periph_clk( g_APinDescription[ulPin].ulPeripheralId ) ;
}
break ;
default:
break ;
}
}
Is there any inconvenient to have the pinMode function also setting the OWER register?