RLPLite on Hydra - reading input

Well, simple thing I’m trying and just cannot really nail it.
I’m leaving all the initialization on .NET, doesn’t really performance on init, so in .NET, on connector 6 I set pin 3 to output and pin 9 to input. Both are connected on the extender, as shown on the photo attached.

Writing pin 3 affects pin 9 state, which is as expected. Here’s a short example of what I mean:



DigitalInput pin9 = extender.SetupDigitalInput(GT.Socket.Pin.Nine, GlitchFilterMode.Off, ResistorMode.Disabled);

DigitalOutput pin3 = extender.SetupDigitalOutput(GT.Socket.Pin.Three, false);

bool boolVar = true;

while (true)
{
    boolVar = !boolVar;

    pin3.Write(boolVar);

    Debug.Print(pin9.Read().ToString());   // This output gives exactly what I write to Pin3
}

Now I’m trying the same thing from RLPLite (with all the same .net settings for pins).
Here’s an example of what I’m doing:



 #define RegA      (AT91_CAST(AT91PS_PIO) 	0xFFFFF400) // (PIOA) Base Address
 #define RegD      (AT91_CAST(AT91PS_PIO) 	0xFFFFFA00) // (PIOD) Base Address

const unsigned int Pin17 = 1 << 17;
const unsigned int Pin27 = 1 << 24;

while(1)
{
	RegD->PIO_CODR = Pin17;     //clears output. This is pin 3 on connector #6
	
	//Delay
	for(i=0; i<14285393; i++){}
			
	RegD->PIO_SODR = Pin17;     //set output data to 1;
			
	//Delay
	for(i=0; i<14285393; i++){}
}

Now how do I correctly read the input from the register (PIOA)? According to datasheet, [em]"(PIO_PDSR) Pin Data Status Register"[/em] should give my the data on required register, something like [em]RegA->PIO_PDSR & Pin24[/em] for PA24 on PIOA. But according to what I see, PIO_PDSR doesn’t really reflect anything I expect.

Now I’m sure I’m doing something wrong or I just doesn’t understand the purpose of PIO_PDSR and there should be different variable…

Thanks!

Are you running this on bare metal? IE without NETMF? Or are you loading this using RLP?

If you are using RLP then you cant have a never ending loop, as control will never return to NETMF and it will die…

I’m running it from NETMF.
The problem with while(1) loop I already had and solved. Yes, if you enter RLP mode with while(1) loop, you cannot deploy new code anymore - the solution is FW update. But in order to avoid such problems, I’m NOT entering RLP mode on the boot. I’m using button module as a trigger for RLP, so after simple reset I’m back to NETMF.

Anyways, the code here is only for an example - it’s not the problem. I’m stuck with reading pin status. So either I’m using incorrect output commands or incorrectly reading from for input.

Where are you putting that code?

I guess I must go find the Hydra’s datasheet… :slight_smile:

Datasheet of the CPU used on Hydra (AL91SAM9RL64) - http://www.atmel.com/Images/doc6289.pdf

For example, I’m using


return(RegA->PIO_PDSR & Pin24);

which should return status of the input.

Or


return(RegA->PIO_PDSR);

which should return status of the whole register. As I understand, binary representation of this number will give status of each bit, while each bit represent each pin controlled by that register.

But how are you calling the RLP that returns with the register, while the other rlp code is in an endless loop?

Or are you using a button as input?

It looks like the correct register.

What do you see?

I assume that the PIO clock is enabled…

Only one RLP code is running (AFAIK there’s no option to execute more then one RLP code).
The endless loop I showed in code example, is irrelevant. It was just for example of toggling on and off some pin.
I’m using the button to execute one RLP code.
Now about the clock- I also assume. I never actually enabled it manually, but I assume it is enabled at some point of the boot. But it’s a good point, I will definitely recheck it. Any chance you remember how do I enable/disable or check its status?

Well, it looks like the PIO clock Is enabled, thought there’s again output I don’t real.y understand.
Here’s the code I use to read clock status:


return(AT91C_BASE_PMC->PMC_PCSR);

It returns 4271164 = 10000010010110000[em]1111[/em]00

Now the bold bits are for PIO A, B, C and D (according to the .h file and the datasheet which screenshot I attached)


 #define AT91C_ID_PIOA   ( 2) // Parallel IO Controller A
 #define AT91C_ID_PIOB   ( 3) // Parallel IO Controller B
 #define AT91C_ID_PIOC   ( 4) // Parallel IO Controller C
 #define AT91C_ID_PIOD   ( 5) // Parallel IO Controller D

Now if I try to disable the clock on all 4 PIO’s using the following code, I expect the bold bits to be off.


AT91C_BASE_PMC->PMC_PCDR = AT91C_ID_PIOA;
AT91C_BASE_PMC->PMC_PCDR = AT91C_ID_PIOB;
AT91C_BASE_PMC->PMC_PCDR = AT91C_ID_PIOC;
AT91C_BASE_PMC->PMC_PCDR = AT91C_ID_PIOD;

return(AT91C_BASE_PMC->PMC_PCSR);

But what I actually get is 4271160 = 10000010010110000[em]1110[/em]00
Note that only one bit got off, which looks like only the clock of PIOA went off.

Am I doing something wrong? Or I just misunderstood the datasheet???

OK, I figured it out. I was doing everything right, but I was using pins which were multiplexed.
Anyways, thanks for helping.

@ Stargazer - You may want to check PIO_PSR to make sure the PIO controller does in fact control the pins you are using and not the peripheral see 31.4.2 in the manual. Is the register class available for Hydra?

Looks like we posted at the same time!