Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: PIO Controller Problem
PostPosted: Wed Dec 07, 2011 1:19 am 
Offline

Joined: Sun Nov 13, 2011 6:57 pm
Posts: 4
Dear Sirs and Madams!

The following problem is driving me nuts! I am trying to configure Port B to be controlled from CPU and I therefore I write 0xffffffff to PIO_PER and PIO_OER, as seen in following C function:[code]void initPIO_Port(const AT91PS_PIO port)
{
if(port==0)
return;

port->PIO_PER=0xffffffff;
port->PIO_OER=0xffffffff;
} // initPIO_Port[/code]Then I step through this function in WinIDEA, but the register PIO_PSR (status register) does not change. What is wrong??


Top
 Profile  
 
 Post subject: Re: PIO Controller Problem
PostPosted: Wed Dec 07, 2011 1:56 am 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
Perhaps you are not enabling the PMC clock for PIOB, that would make peripheral registers unresponsive.

You haven't provided enough context to help you much more.

What CPU, what OS, what kind of initialization you've done, etc. ?


Top
 Profile  
 
 Post subject: Re: PIO Controller Problem
PostPosted: Wed Dec 07, 2011 2:08 am 
Offline

Joined: Sun Nov 13, 2011 6:57 pm
Posts: 4
[quote="CptTitanic"]Perhaps you are not enabling the PMC clock for PIOB, that would make peripheral registers unresponsive.

You haven't provided enough context to help you much more.

What CPU, what OS, what kind of initialization you've done, etc. ?[/quote]Thanks for your reply. The CPU is AT91SAM9260E-JS, the board is a custom board from Faculty of Computer and Information Sciences from Ljubljana, Slovenia, EU and all init code, posted below, was made by some lecturer. I am rather newbie with ARM CPUs and I am really lost. Here is bootup init code:[code]#include "main.h"
#include "AT91SAM9260.h"

//*----------------------------------------------------------------------------
//* \fn printk
//* \brief This function is used to send a string through the DBGU channel (Very low level debugging)
//*----------------------------------------------------------------------------
void printk(char *buffer) // \arg pointer to a string ending by \0
{
while(*buffer != '\0') {
while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU));
AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, *buffer++);
}
}

void CPU_Init()
{
AT91PS_PMC pPmc = AT91C_BASE_PMC;

///////////////////////////////////////////////////////////////////////////
// Init PMC Step 1. Enable Main Oscillator
// Main Oscillator startup time is board specific:
// Main Oscillator Startup Time worst case (18MHz) corresponds to 1,4ms
// (0x08 for AT91C_CKGR_OSCOUNT field)
///////////////////////////////////////////////////////////////////////////
pPmc->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x8 <<8) | AT91C_CKGR_MOSCEN ));
// Wait Main Oscillator stabilization
while(!(pPmc->PMC_SR & AT91C_PMC_MOSCS));
// Switch to main ocilator
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_MAIN_CLK;

///////////////////////////////////////////////////////////////////////////
// Init PMC Step 2.
// Set PLL to 192 MHz and UDP Clock to 48MHz
// PLL Startup time depends on PLL RC filter: worst case is choosen
// UDP Clock (48,0MHz) is compliant with the Universal Serial Bus
// Specification (+/- 0.25% for full speed)
/* -Setup the PLL A */
AT91C_BASE_CKGR->CKGR_PLLAR = (AT91C_CKGR_SRCA) |
((124 << 16) & AT91C_CKGR_MULA) |
(AT91C_CKGR_PLLACOUNT) |
(AT91C_CKGR_OUTA_2) |
(12);

while (!(pPmc->PMC_SR & AT91C_PMC_LOCKA));
// Wait until the master clock is established for the case we already
// turn on the PLL

///////////////////////////////////////////////////////////////////////////
// Init PMC Step 3.
// Selection of Master Clock MCK equal to (Processor Clock PCK) PLL/2=48MHz
///////////////////////////////////////////////////////////////////////////

AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_CSS_PLLA_CLK | AT91C_PMC_PRES_CLK | AT91C_PMC_MDIV_2;
// Wait until the master clock is established
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );

// Configure DBGU
AT91F_US_ResetRx((AT91PS_USART)AT91C_BASE_DBGU);

AT91F_US_Configure(
(AT91PS_USART)AT91C_BASE_DBGU, // DBGU base address
AT91B_MASTER_CLOCK, // 96 MHz
AT91C_US_ASYNC_MODE, // mode Register to be programmed
AT91B_DBGU_BAUD_RATE, // baudrate to be programmed
0 // timeguard to be programmed
);
// Open PIO for DBGU
AT91F_DBGU_CfgPIO();
// Enable Transmitter
AT91F_US_EnableTx((AT91PS_USART)AT91C_BASE_DBGU);
}[/code]


Top
 Profile  
 
 Post subject: Re: PIO Controller Problem
PostPosted: Wed Dec 07, 2011 4:27 am 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
Yes, so you're not initializing the clock on the peripheral device you wish to configure.

AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOB); // Enable Clock to PIOB

See Page 24
http://www.atmel.com/dyn/resources/prod ... oc6221.pdf


Top
 Profile  
 
 Post subject: Re: PIO Controller Problem
PostPosted: Wed Dec 07, 2011 9:15 am 
Offline

Joined: Sun Nov 13, 2011 6:57 pm
Posts: 4
[quote="CptTitanic"]Yes, so you're not initializing the clock on the peripheral device you wish to configure.

AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOB); // Enable Clock to PIOB

See Page 24
http://www.atmel.com/dyn/resources/prod ... oc6221.pdf[/quote]Ok, thanks for hint, I've checked the docs and got following peripheral id numbers:
Port A - 2
Port B - 3
Port C - 4
According to this info, I've renamed void initPIO_Port(const AT91PS_PIO port) to void initPIO_PortPins(const AT91PS_PIO port) and added void initPIO_Port(const AT91PS_PIO port, const unsigned int iPeripheralId) method:
void initPIO_PortPins(const AT91PS_PIO port)
{
if(port==0)
return;

port->PIO_PER=0xffffffff;
port->PIO_OER=0xffffffff;
} // initPIO_Port

void initPIO_Port(const AT91PS_PIO port,
const unsigned int iPeripheralId)
{
// AT91PS_SYS pSystemPeripheral=AT91C_BASE_SYS;
AT91PS_PMC pPMController=AT91C_BASE_PMC;

//pSystemPeripheral->PMC_PCER|=(1<<iPeripheralId); // Enable Clock to selected PIO
pPMController->PMC_PCER|=(1<<iPeripheralId); // Enable Clock to selected PIO
initPIO_PortPins(port);
}

But it still does not work! All Power Management Controller (Clock and etc) is done in previous code from lecturer, why still does not work??


Top
 Profile  
 
 Post subject: Re: PIO Controller Problem
PostPosted: Thu Dec 08, 2011 6:50 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
Using '|=' against PMC_PCER is not recommended, it's a write-only register, just write the bits you want enabled, and confirm what value is in PMC_PCSR

You might want to add some code to dump the address and content of registers you want to examine.

Try accessing the PIOB registers directly, or via the debugger.

I don't see the parameters you're calling these routines with, you need to confirm the value of 'port' is correct.

Step the code, and watch what the registers are set to.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: