cancel
Showing results for 
Search instead for 
Did you mean: 

using the SPI INTERFACE in olimex stm32-p103 dev board

abhinavbose87
Associate II
Posted on December 03, 2009 at 07:29

using the SPI INTERFACE in olimex stm32-p103 dev board

20 REPLIES 20
pranamesh
Associate II
Posted on May 17, 2011 at 13:28

ok, edison gave you some good starting tips which you can (should) follow. Below are a list of action items that you can follow to get your thing up and running....again going by your newbie status. (this is the cheaper/opensource version of what edison has said)

1: buy a dev kit. I bought mine from olimex 103STK and you can do the same. judging by your nick name, I believe you are from india. there are some importers of this kit and is available at around 8000 INR.

2: buy a JTAG wiggler. I bought ARM-USB-OCD. You will need this to program the hardware unit after you compile the code/firmware (around 3500 INR)

3: From the olimex dev kit, you will also receive a Eclipse based compiler/IDE for this MCU. Install it (works on windows/linux; I used windows). Using this you should be able to write your code in ''C'' and compile it using the free GNU compiler (gets installed along with the whole thing)

4: Download the blinking led example from olimex site and compile it under the above Eclipse IDE and you should get the main.bin or something like it as the firmware

5: download it using the JTAG and !wow!:-D you should be able see the led in the dev kit blinking. be very happy about achieving this far ;)

6: start using the sample SPI and check using the logic analyzer if you have one (or cook up something of your own to see the signals if you need to)

7: utilize the knowledge till now in modifying the SPI example. Do the following for the LCD after you know that the SPI is working

8: read the initialization instructions for the LCD and send it across the LCD. (you can use the examples I gave above).

9: read the data/command instructions for the LCD and send it across the LCD for actually displaying the character/dots as per your need.

10: if you want to be a little adventurous, you can also use two GPIO pins to simulate an SPI ;-), one for the data and one for the clock.

Hope that helps

abhinavbose87
Associate II
Posted on May 17, 2011 at 13:28

hi in one of the links you asked me to follow is

http://github.com/halfbyte/lcddogmspi

u asked me to port the code directly for the application.but i had some errors which i think are because of the file included called wconstants.h.whan i looked up,they were defined in arduino library and the entire code is built for that.i dont know what arduino is.but i just want to know if i can still proceed to use the library for my application....

tomas23
Associate II
Posted on May 17, 2011 at 13:28

abhinavbose87,

without understanding of (thus reading) the code, you can't simply take its parts and re-use them. So take your time.

If you want something specific, give us details.

pranamesh
Associate II
Posted on May 17, 2011 at 13:28

the file LCDdogmSPI.cpp in the mentioned site clearly defines the lcd init commands and other functions. I had asked you to port the code for STM32. That code will not work if you try to use it *as it is* in the STM32 platform.

try to take the LCDdogmSPI::init() function and modify it in the STM32 spi example and the lcd should work. in case there are some issues related to init of the lcd cross check the init commands with that of the lcd driver ST7036 (I assume EM DOG lcds use this driver, you can check the datasheet)

Adrino is another microcontroller platform using the ATmega mcu. you need not dwell in it for your purpose.

abhinavbose87
Associate II
Posted on May 17, 2011 at 13:28

no i still dont understand you.i think i already told you i am totally new to embedded programing.so please, what do u mean when you say port the code for SPI example?without reading the entire .cpp code,how can i look for similar functions in the spi example?(if thats what u meant).even then i have to read the entire code in SPI example.its too long with many function calls.i hope u did not mean that.can u explain in simpler terms please.

sorry for the trouble.glad if u can help.

abhinavbose87
Associate II
Posted on May 17, 2011 at 13:28

edison and pranamesh thanks a lot for ur advice and directuions.i have started to read the code and want to do it in a step wise manner.so my first task is to get a demo program to work on the board.so i used the sample demo code given and loaded it.it worked..

now i want to edit that program to first implement SPI2 port transfer without considering the other part(LCD).so i want to know how to check the board to find out if my spi2 port is active or not, so that i can first verify it and then do coding for LCD...

pranamesh
Associate II
Posted on May 17, 2011 at 13:28

well, even if you are a new to embedded, you can stilll utilize your programming skills from the ''PC with OS environment''. below would be some steps which you can take as guide line for ''porting'', but you got to walk to path yourself ;)

First make sure you try any SPI example running successfully on your board, to understand SPI as such. This would give you experience in sending and receiving of data using SPI.(though receiving is not important in the lcd application many a times)

Then check the init code of LCDdogmSPI::init()

first you need to init the SPI (as in the SPI examples

 

 

set your GPIOs first here

 

..

 

..

 

..

 

 

// SPI1 configuration

 

SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

 

SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

 

SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;

 

SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;

 

SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

 

SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

 

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;

 

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

 

SPI_InitStructure.SPI_CRCPolynomial = 7;

 

SPI_Init(SPI1, &SPI_InitStructure);

 

 

// Enable SPI1

 

SPI_Cmd(SPI1, ENABLE);

 

 

then there are commands that you need to send using SPI to initialize your LCD before you can write any display data as in the LCDdogmSPI example

 

commandWrite(LCDCMD_FUN_REG_2 | linesreg); //function set

 

delay(1);

 

commandWrite(LCDCMD_FUN_REG_2 | linesreg); //function set

 

delay(1);

 

commandWrite(LCDCMD_BIAS_SET);

 

commandWrite(LCDCMD_POWER_CTL);

 

commandWrite(LCDCMD_FOLLOWER_CTL);

 

commandWrite(LCDCMD_CONTRAST_SET);

 

commandWrite(LCDCMD_ON);

 

commandWrite(LCDCMD_CLR);

 

commandWrite(LCDCMD_ENTRY_MODE_SET);

 

commandWrite(LCDCMD_HOME);

 

you have to change the commandWrite() method to something that your board (with STM32) can use like changing it to something like this

 

void LCDdogmSPI::commandWrite(char value) {

 

// Enable display controller (active low) -> LCD_E low

 

GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_RESET);

 

 

// command - D/S low or high

 

GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET);

 

 

///// SEND SPI /////

 

// Loop while DR register in not emplty

 

while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET);

 

 

// Send byte through the SPI1 peripheral

 

SPI_SendData(SPI1, value);

 

 

// Wait to receive a byte

 

while(SPI_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET);

 

///// SEND SPI END /////

 

 

 

// Disable display controller -> LCD_E high

 

GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_SET);}

 

see this is how you need to port and you have to do this incrementally and check at each point if it works. Don't do it in one go, as in most cases it doesn't work unless you are very experienced. finding problems in embedded programming is much more difficult than in the PC domain.

as some earlier said this requires a lot of patience and hard work, so burn your night lamp ;)

abhinavbose87
Associate II
Posted on May 17, 2011 at 13:28

ok . i edited the program and compiled it without errors.i loaded into the board and ran it.the error was

target state: halted

target halted due to breakpoint, current mode: handler hardfault

xPSR:0x01000003 pc:0x4a445f8ce

any idea what this means???

pranamesh
Associate II
Posted on May 17, 2011 at 13:28

use SPI1 and SPI2 back to back (interchange MOSI and MISO). else use the logic analyzer if you have one.

pranamesh
Associate II
Posted on May 17, 2011 at 13:28

Did you first run the unedited example to see if you are able to run it?. Your edited code created an exception at run-time. just compiling correctly doesn't guarantee a correct run-time behavior. assuming you don't have a jtag debugger (or don't know how to use it; its complicated for a free open-source setup), do a smaller set of changes in the original working code (sometimes single line changes!) and compile and do the testing. thats bare bone debugging. you can also pump data in an usart and connect it to a pc and see the dumps to check which line is failing.

But you please try harder and think more on how to solve the problems. I hope you realize that we have now moved away from your original problem and got into general programming/debugging issues for which you need to study books/tutorials on embedded programming. So please do some homework and you should be able to solve these problems easily with time and effort. :-[