LCD trouble using axiom's CSMB12 with PBMCUSLK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LCD trouble using axiom's CSMB12 with PBMCUSLK

1,585 Views
craigc
Contributor I

PLEASE HELP!!!

 

I am extremely frustrated. I'm a student who's professor doesn't care to teach us how to do this. I have been unable to display to the 8x2 lcd screen included with the PBMCUSLK AXM-0392 REV D Development board. i'm using axiom's CSMB12 daughter board. the microcontroller is the MC9S12DT256MFUE.

 

From what i've discovered so far:

The lcd uses the SPI interface. It is driven by a serial to parallel shift register 74HC595D. It requires that the LCD_EN jumpers be installed and the SS_SEL Jumper to be connecting SS* instead of GPIO. Axioms CSMB12 board labels the MOSI0,MISO0,SCK0,and SS0 as PM<#> which leads one to believe that it is connected to Port M, but the microcontroller datasheet shows these connecting to Port S.

 

I set up the registers and used some example code from my text to try and write a character to the lcd screen. 

 

void main{

 // Initialize the spi interface

openspi0(void);

 

for(;:smileywink:{    

putcspi0('H');       

delay1ms(1);}     

 

for(;:smileywink:{  } /* loop forever */ 

/* please make sure that you never leave main */

}

//Here is the function to set up the spi registers.

void openspi0(void){ 

SPI0BR = 0x10;                  // set baud rate   

SPI0CR1 = 0x50;                 // enable SPI, data shift on SCK’s rising edge, master mode   

SPI0CR2 = 0x02;                 // disable bidirectional mode, SPI stops in wait mode   

WOMS = 0x00;                    // enable Port S pull-up   

DDRS = 0xE2;

}

 

// Function to desplay a character.

void putcspi0 (char cx){   

char temp;       

while(!(SPI0SR & 0x20));        // wait until write is permissible   

SPI0DR = cx;                    // output the byte to the SPI   

while(!(SPI0SR & 0x80));         // wait until write operation is complete   

temp = SPI0DR;                  // clear the SPIF flag

}

 

 

Thanks in advance for the help!

Labels (1)
Tags (1)
0 Kudos
8 Replies

911 Views
bigmac
Specialist III

Hello,

 

This problem is more complex than simply initialising the SPI module, and writing byte values to the shift register.

 

  1. The 'HC595 has a strobe input at pin 12 (RCK on my datasheet).  Presumably this is connected to a GPIO pin, or the /SS pin associated with the SPI module.  The strobe process requires a positive edge following the serial transfer of each byte, accomplished either with automatic SS SPI module configuration, or explicit GPIO manipulation.
    .
  2. The LCD pins may be mapped to the shift register outputs in a variety of ways.  The LCD connections could be for either 8-bit mode, or for 4-bit mode.  In the first case the 'E' and 'RS' control signals would have their own GPIO pins on the MCU.  However, if there are only four data connections to the display, 'E' and 'RS' may well be connected to the shift register.  The actual hardware configuration will substantially affect your code.  For 4-bit mode, each byte is sent as two 4-bit nybbles.  Additionally, the 'E' signal will need to be strobed, by sending each nybble twice, firstly with the E-bit high, and then with the E-bit low.  Following the send of each byte or nybble, a delay is necessary (the LCD is very slow).
    .
  3. The LCD will require its own initialisation process before it can display characters.  Initialisation for 4-bit mode is more complex than for 8-bit mode.  This does not appear to have been incuded within your code.

You will need to ascertain the hardware configuration before you will be able to write the code.  For this you will need the schematic.  Have you checked whether Axiom publish any LCD driver code for their board?

 

Regards,

Mac

 

0 Kudos

911 Views
AirDragon
Contributor III

Ouch, why did the prof have to go ahead and start off with a SPI based LCD? I mean, I know the LCD itself is parrallel, but the addition of the shift register makes life more difficult than it should be!

 

 

Oh, think I found it. You didn't actually enable the SPI to begin with, Lol:

 

You have:

   SPI0CR1 = 0x50

 

Probably should be:

   SPI0CR1 = 0xD0

 

Since SPI0CR1 bit 7 is the SPIE bit...

 

By the way, do you have a copy of the device manual?

 

 

Edit: Doh, read the register map wrong.

 

 

0 Kudos

911 Views
craigc
Contributor I

I'd like to add that when debugging, the program stops at "while(!(SPI0SR & 0x80))" within the putcspi0 function. This is checking a flag in the status register to see if the data transfer is complete. this flag never clears.

0 Kudos

911 Views
AirDragon
Contributor III

craigc, after going through the 74HC595D data sheet, my diagnosis is "what the heck?"

 

The operation you currently have is waiting on input from the shift register... but after consulting the datasheet I see no way how that would be possible.

 

Try omitting the while( !(SPI0SR & 0x80) ) line and see if anything happens.

 

0 Kudos

911 Views
kef
Specialist I

AirDragon,

 

no, operation is waiting for transfer complete. How many bits is clocked out, so meny bits is clocked in. In master SPIF flag is set after transfer is complete (both out and in). Of course to make it working as transfer complete flag, you need to clear SPIF after each transfer by reading status reg followed by read of data reg. Craifgc's code looks well.

 

Craigc,

 

I don't know how old is your board and how faulty is MCU on it. It makes sense to check erratas.

Also could you verify if MODF flag is set or clear? It shouldn't be set, but somewhen long time ago (don't remember on which of HC11/HC12D or maybe S12D64) I saw MODF set after enabling SPI in master mode, which prevented switching to master mode. Solution was to read status reg before writing to SPICR1. This is normal sequence to clear MODF flag.

0 Kudos

911 Views
AirDragon
Contributor III

Well I guess that just goes to show how much I've messed with the SPI module... one of these days I'll have to try getting my own shift register and play with it.

 

Thanks kef

0 Kudos

911 Views
AirDragon
Contributor III

This might be a dumb question, but did you check to make sure that the CodeWarrior target isn't set to "full chip simulation"?

0 Kudos

911 Views
craigc
Contributor I

nice thought, wish it was that easy!

 

it's set to the P&E Multilink/Cyclone Pro. I when i start the debugger it tells me its loading the software .... so not it. 

0 Kudos