Hi Guys, I'm new at the MPC5645S and PPC Assembler. I've read the reference manual on the SIUL and can't seem to turn on PORT A for output. Here's my small code, please let me know what I'm doing wrong.
.equ base 0xC3F90000
.equ porta_dir base+0x0040
.equ porta_out base+0xC000 ;Parallel mode
lis r30,porta_dir@h
ori r30,r30,porta_dir_l
li r16,64+1024+4096+8192
sth r16,0(r30) ;Set ALL PORT A pins to output
sth r16,2(r30)
sth r16,4(r30)
sth r16,6(r30)
sth r16,8(r30)
sth r16,10(r30)
sth r16,12(r30)
sth r16,14(r30)
sth r16,16(r30)
sth r16,18(r30)
sth r16,20(r30)
sth r16,22(r30)
sth r16,24(r30)
sth r16,26(r30)
sth r16,28(r30)
sth r16,30(r30)
lis r28,0xFFFFFFFF@h
ori r28,r28,0xFFFFFFFF@l
lis r29,porta_out@h
ori r29,r29,porta_out@l
stw r28,0(r29)
With my experience with other micro controllers I just set PORTA to output and write 0xFFFFFFFF to the PORTA output register and all the LEDS on PORTA turn on.
I'm just learning about the MPC5645S and PPC assembler. Please let me know why PORTA is not outputting.
Thanks guys and hope to hear from you soon.
Pete
Solved! Go to Solution.
Hi Pete,
don't be confused by bit numbering. It's big endian with "MSB 0" bit numbering convention.
To set OBE, you need to use 0x0200 or 0b0000001000000000 value.
All you need to do is to enable SIUL module in Mode Entry. I suppose you have already done this because write to any SIUL register would trigger an exception if it is not enabled.
This is minimalist C code which works:
/* Enter RUN0 with PLL as sys clk (64 MHz) with 8 MHz crystal reference. */
ME.MER.R = 0x0000001D; /* Enable DRUN, RUN0, SAFE, RESET modes */
CGM.FMPLL[0].CR.R = 0x00200100; /* 8MHz xtal: Set PLL0 to 128 MHz, fsys=PLL/2 */
ME.RUNPC[0].R = 0x000000FE; /* enable peripherals run in all modes */
ME.RUN[0].R = 0x001F0074; /* RUN0 cfg: IRCON,OSC0ON,PLL0ON,syclk=PLL */
/* Mode Transition to enter RUN0 mode: */
ME.MCTL.R = 0x40005AF0; /* Enter RUN0 Mode & Key */
ME.MCTL.R = 0x4000A50F; /* Enter RUN0 Mode & Inverted Key */
while (ME.GS.B.S_MTRANS) {} ; /* Wait for mode transition to complete */
while(ME.GS.B.S_CURRENTMODE != 4) {}; /* Verify RUN0 is the current mode */
SIU.PCR[0].R = 0x200; /* Set OBE for PA0 */
SIU.GPDO[0].R = 1; /* Toggle PA0 several times */
SIU.GPDO[0].R = 0;
SIU.GPDO[0].R = 1;
SIU.GPDO[0].R = 0;
Regards,
Lukas
Hi Pete,
I can see that you want to write this value to PCRn registers:
li r16,64+1024+4096+8192
The value in binary is:
0011010001000000
And this really does not hit the OBE bit to enable output buffer.It also writes to PA[1:0] field which then selects alternate function, not GPIO.
To set OBE (in fact, nothing else is needed), you need to write value 0x0200 to PCR registers.
Regards,
Lukas
Hi Lukas, Where did you get your info from? In the MPC5645S reference Manual section 43.5.3.8 it says bit 6 is the OBE bit. Bit 6 = 64 in decimal. I tried your 0x0200 which = 512 which is bit 9 and the manual says bit 9 in not used. I tried it anyway and still nothing on PORTA.
Do I have to set up any peripheral clocks or something else to get the ports to work?
Pete
Hi Pete,
don't be confused by bit numbering. It's big endian with "MSB 0" bit numbering convention.
To set OBE, you need to use 0x0200 or 0b0000001000000000 value.
All you need to do is to enable SIUL module in Mode Entry. I suppose you have already done this because write to any SIUL register would trigger an exception if it is not enabled.
This is minimalist C code which works:
/* Enter RUN0 with PLL as sys clk (64 MHz) with 8 MHz crystal reference. */
ME.MER.R = 0x0000001D; /* Enable DRUN, RUN0, SAFE, RESET modes */
CGM.FMPLL[0].CR.R = 0x00200100; /* 8MHz xtal: Set PLL0 to 128 MHz, fsys=PLL/2 */
ME.RUNPC[0].R = 0x000000FE; /* enable peripherals run in all modes */
ME.RUN[0].R = 0x001F0074; /* RUN0 cfg: IRCON,OSC0ON,PLL0ON,syclk=PLL */
/* Mode Transition to enter RUN0 mode: */
ME.MCTL.R = 0x40005AF0; /* Enter RUN0 Mode & Key */
ME.MCTL.R = 0x4000A50F; /* Enter RUN0 Mode & Inverted Key */
while (ME.GS.B.S_MTRANS) {} ; /* Wait for mode transition to complete */
while(ME.GS.B.S_CURRENTMODE != 4) {}; /* Verify RUN0 is the current mode */
SIU.PCR[0].R = 0x200; /* Set OBE for PA0 */
SIU.GPDO[0].R = 1; /* Toggle PA0 several times */
SIU.GPDO[0].R = 0;
SIU.GPDO[0].R = 1;
SIU.GPDO[0].R = 0;
Regards,
Lukas
Hi Lukas, thank you so much for your help. My ports are working now. I have to get used to BIG ENDIAN now because all the micro controllers I've worked with used LITTLE ENDIAN.
Have a great day
Peter