Monday, July 29, 2013

connecting ST7565R LCD to BLE112

After playing around with BLE112, connecting it to my ATMEGA644P via UART I found a post about programming BLE112 with C.

http://blog.bluetooth-smart.com/2012/09/11/programming-the-ble112-with-c-code-using-iar/

After that Ive read CC2540 documentation and realized that this little module got everything what I need in my project - and even more.

First of all Bluegiga offers BGSCRIPT to program BLE112. Its very simple and got a lot of limitations, of course its sufficient to do simple programming, but nothing more. you even cant create functions.

I was very pleased that I can use C language to program this chip. You need IAR which is not free, however you can easily request 30 days trail or kickstart edition which is limited to 4kb of code (which is insufficient …)
Just use 30 day trial or find other way of getting IAR ;)
Trail version 8.20.2 runs just fine in VMWare fusion with all debugging capabilities as well.


Then you need sample BLE apps with BLE stack. Just search for it on TI site: BLE-CC254x-1_3_2.zip

After that you are ready to go.

ST7565R LCD is 3.3v - same as BLE112, so just connect it to the BLE. I used 4 pins - P0.2 P0.3 P0.4 P0.5
I still got no BLE breakboard so I had to solder cables right to BLE :) Its not very complicated task - an extra hand is recommended however.


Next find a ST7565R library - I used: https://github.com/adafruit/ST7565-LCD
C is not my "everyday" language so I spent two hours trying to compile it with IAR. After some modifications I was able to compile it using IAR.


Things to remember when converting code from AVRGCC or similar to IAR C to compile for CC2540:



  • There is no (or I cant find how to use it - even __delay_cycles) delay, sleep or what so ever function, so I used:

    #define F_CPU 32768000
    #define _delay_us(us) __delay_cycles(((us * F_CPU)/1e6) + 0.5)#define _delay_ms(ms) __delay_cycles(((ms * F_CPU)/1e3) + 0.5)
  • setting port direction you need to use PxDIR and not DDRx (where x is port number)
  • if you got compile errors with " Error[Pe020]: identifier "P0DIR" is undefined " just include ioCC2540.h
  • Ive got strange problems with "for" loops when using uint8_t - just convert them to int.
  • uint8_t declaration can be found in stdint.h "Error[Pe020]: identifier "uint8_t" is undefined"



Ive used wiring as follows:

ST7565R          BLE112
CS       ----     P0.2
RST      ----     +3.3v
A0       ----     P0.3
SCLK     ----     P0.4
SDATA    ----     P0.5


Of course that is not sufficient - you still need to supply 3.3v, GND and nine 10uF capicitors on other lines (just check datasheet).

After that you should be able to compile project and display ADAFRUIT logo which is included in stlcd.c.
drawrect, drawcircle should be working as well.



 The problem comes when you want to use drawstring function. When linking you will probably encounter similar error:

Error[e104]: Failed to fit all segments into specified ranges. Problem discovered in segment XDATA_N. Unable to place 2 block(s) (0xc02 byte(s) total)
in 0x96c byte(s) of memory. The problem occurred while processing the segment placement command
"-P(XDATA)XDATA_N=_XDATA_START-_XDATA_END", where at the moment of placement the available memory ranges were "XDATA:1594-1eff"

Solve to this is pretty simple, just go to project options, on the left select C/C++ compiler
and find Preprocessor tab. Then in defined symbols search for INT_HEAP_LEN=3072 and change it to 2048.



after that project should compile without errors.

Here is final version :)




 In next few days I will upload ST7565 IAR library to github.









No comments: