![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Hardware testing for M24SR-DISCOVERY demo PCB. as help to others
Set up to use MB1138 M24SR-DISCOVERY PCB http://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/st25-nfc-rfid-eval-boards/st25-nfc-rfid-eval-boards/m24sr-discovery.html with MBED system. based on https://developer.mbed.org/users/hudakz/code/STM32F103C8T6_Hello/ code and https://developer.mbed.org/users/wim/notebook/m24sr64-nfcrfid-tag-with-i2c-interface/ Which lead me to look at Peter Drescher's work on ILI9341 LCD controller
https://developer.mbed.org/users/dreschpe/code/SPI_TFT_ILI9341/
main.cpp@2:2033db202017, 2016-09-29 (annotated)
- Committer:
- lloydg
- Date:
- Thu Sep 29 11:07:41 2016 +0000
- Revision:
- 2:2033db202017
re jig folders
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lloydg | 2:2033db202017 | 1 | #include "STM32F103RGT6.h" |
lloydg | 2:2033db202017 | 2 | #include "stdio.h" |
lloydg | 2:2033db202017 | 3 | #include "mbed.h" |
lloydg | 2:2033db202017 | 4 | #include "SPI_TFT_ILI9341.h" |
lloydg | 2:2033db202017 | 5 | //#include "string" // errors? |
lloydg | 2:2033db202017 | 6 | #include "Arial12x12.h" |
lloydg | 2:2033db202017 | 7 | #include "Arial24x23.h" |
lloydg | 2:2033db202017 | 8 | #include "Arial28x28.h" |
lloydg | 2:2033db202017 | 9 | #include "font_big.h" |
lloydg | 2:2033db202017 | 10 | // the TFT is connected to SPI pin PB_15, PB_14, PB_13, PB_12, NC, PC_6, mosi, miso, sclk, cs, reset, dc |
lloydg | 2:2033db202017 | 11 | SPI_TFT_ILI9341 TFT(PB_15, PB_14, PB_13, PB_12, NC, PC_6,"TFT"); // mosi, miso, sclk, cs, reset, dc |
lloydg | 2:2033db202017 | 12 | //If your display need a signal for switch the backlight use a aditional IO pin in your program |
lloydg | 2:2033db202017 | 13 | |
lloydg | 2:2033db202017 | 14 | |
lloydg | 2:2033db202017 | 15 | Serial pc(PC_10, PC_11); |
lloydg | 2:2033db202017 | 16 | DigitalOut led1(LED1); |
lloydg | 2:2033db202017 | 17 | DigitalOut led2(LED2); |
lloydg | 2:2033db202017 | 18 | DigitalOut led3(LED3); |
lloydg | 2:2033db202017 | 19 | DigitalOut led4(LED4); |
lloydg | 2:2033db202017 | 20 | DigitalIn joyleft(PB_5); |
lloydg | 2:2033db202017 | 21 | DigitalIn joysel(PB_6); |
lloydg | 2:2033db202017 | 22 | DigitalIn joydown(PB_7); |
lloydg | 2:2033db202017 | 23 | DigitalIn joyright(PB_8); |
lloydg | 2:2033db202017 | 24 | DigitalIn joyup(PB_9); |
lloydg | 2:2033db202017 | 25 | AnalogIn line(BT_RESET); |
lloydg | 2:2033db202017 | 26 | DigitalIn BT_1(BT_GPIO1); |
lloydg | 2:2033db202017 | 27 | //DigitalIn BT_2(BT_RESET); |
lloydg | 2:2033db202017 | 28 | DigitalIn BT_3(BT_POWER_ON); |
lloydg | 2:2033db202017 | 29 | //Timer timer; |
lloydg | 2:2033db202017 | 30 | //int begin, end; |
lloydg | 2:2033db202017 | 31 | int buff[320]; |
lloydg | 2:2033db202017 | 32 | |
lloydg | 2:2033db202017 | 33 | int main() |
lloydg | 2:2033db202017 | 34 | { |
lloydg | 2:2033db202017 | 35 | int state =0; |
lloydg | 2:2033db202017 | 36 | int pointx =0; |
lloydg | 2:2033db202017 | 37 | int i; |
lloydg | 2:2033db202017 | 38 | //timer.start(); |
lloydg | 2:2033db202017 | 39 | //int pointy =0; |
lloydg | 2:2033db202017 | 40 | TFT.claim(stdout); // send stdout to the TFT display |
lloydg | 2:2033db202017 | 41 | //TFT.claim(stderr); // send stderr to the TFT display |
lloydg | 2:2033db202017 | 42 | TFT.background(Black); // set background to black |
lloydg | 2:2033db202017 | 43 | TFT.foreground(White); // set chars to white |
lloydg | 2:2033db202017 | 44 | TFT.set_orientation(1); // 1 to set correct for m24sr-descovey |
lloydg | 2:2033db202017 | 45 | TFT.newcls(); // clear the screen |
lloydg | 2:2033db202017 | 46 | TFT.set_font((unsigned char*) Arial24x23); // select font 2 |
lloydg | 2:2033db202017 | 47 | //TFT.line(0, 0, TFT.width(), TFT.height(), Red); |
lloydg | 2:2033db202017 | 48 | //TFT.fillrect(200, 200, 100, 100, White); |
lloydg | 2:2033db202017 | 49 | printf("width (%d)\n", TFT.width()); |
lloydg | 2:2033db202017 | 50 | printf("height(%d)\n", TFT.height()); |
lloydg | 2:2033db202017 | 51 | printf("columns (%d)\n", TFT.columns()); |
lloydg | 2:2033db202017 | 52 | printf("rows(%d)\n", TFT.rows()); |
lloydg | 2:2033db202017 | 53 | wait(5); |
lloydg | 2:2033db202017 | 54 | TFT.locate(0,100); |
lloydg | 2:2033db202017 | 55 | while(1) { |
lloydg | 2:2033db202017 | 56 | if(!joyleft) { |
lloydg | 2:2033db202017 | 57 | printf(" left\n"); |
lloydg | 2:2033db202017 | 58 | pc.printf(" left\n"); |
lloydg | 2:2033db202017 | 59 | TFT.cls(); |
lloydg | 2:2033db202017 | 60 | state =1; |
lloydg | 2:2033db202017 | 61 | } |
lloydg | 2:2033db202017 | 62 | if(!joyright) { |
lloydg | 2:2033db202017 | 63 | printf(" right\n"); |
lloydg | 2:2033db202017 | 64 | pc.printf(" right\n"); |
lloydg | 2:2033db202017 | 65 | TFT.cls(); |
lloydg | 2:2033db202017 | 66 | state =2; |
lloydg | 2:2033db202017 | 67 | } |
lloydg | 2:2033db202017 | 68 | if(!joyup) { |
lloydg | 2:2033db202017 | 69 | printf(" up\n"); |
lloydg | 2:2033db202017 | 70 | pc.printf(" up\n"); |
lloydg | 2:2033db202017 | 71 | TFT.cls(); |
lloydg | 2:2033db202017 | 72 | state =3; |
lloydg | 2:2033db202017 | 73 | } |
lloydg | 2:2033db202017 | 74 | if(!joydown) { |
lloydg | 2:2033db202017 | 75 | led4 = !led4; |
lloydg | 2:2033db202017 | 76 | printf(" down\n"); |
lloydg | 2:2033db202017 | 77 | pc.printf(" down\n"); |
lloydg | 2:2033db202017 | 78 | state =4; |
lloydg | 2:2033db202017 | 79 | } |
lloydg | 2:2033db202017 | 80 | if(!joysel) { |
lloydg | 2:2033db202017 | 81 | printf(" sel\n"); |
lloydg | 2:2033db202017 | 82 | pc.printf(" sel\n"); |
lloydg | 2:2033db202017 | 83 | state =5; |
lloydg | 2:2033db202017 | 84 | } |
lloydg | 2:2033db202017 | 85 | |
lloydg | 2:2033db202017 | 86 | switch (state) { |
lloydg | 2:2033db202017 | 87 | case 1: |
lloydg | 2:2033db202017 | 88 | led1 = !led1; |
lloydg | 2:2033db202017 | 89 | TFT.locate(0,0); |
lloydg | 2:2033db202017 | 90 | printf("BT_1! (%x)\n", BT_1.read()); |
lloydg | 2:2033db202017 | 91 | printf("BT_3! (%x)\n", BT_3.read()); |
lloydg | 2:2033db202017 | 92 | wait(1); |
lloydg | 2:2033db202017 | 93 | break; |
lloydg | 2:2033db202017 | 94 | case 2: |
lloydg | 2:2033db202017 | 95 | led2 = !led2; |
lloydg | 2:2033db202017 | 96 | TFT.locate(0,0); |
lloydg | 2:2033db202017 | 97 | printf("val! (%d)\n", line.read_u16()); // 3v3 = +65,535 |
lloydg | 2:2033db202017 | 98 | printf("val! (%f)\n", line.read()); // 3v3 = ??? |
lloydg | 2:2033db202017 | 99 | printf("val! (%x)\n", line.read_u16()); |
lloydg | 2:2033db202017 | 100 | pc.printf("val! (%f)\n", line.read_u16()); |
lloydg | 2:2033db202017 | 101 | wait(1); |
lloydg | 2:2033db202017 | 102 | break; |
lloydg | 2:2033db202017 | 103 | case 3: |
lloydg | 2:2033db202017 | 104 | TFT.newcls(); // clear the screen |
lloydg | 2:2033db202017 | 105 | //begin = timer.read_us(); |
lloydg | 2:2033db202017 | 106 | for(i=0; i<320; i++) { |
lloydg | 2:2033db202017 | 107 | buff[i] = (int) (TFT.height()-(line.read()*TFT.height())); |
lloydg | 2:2033db202017 | 108 | } |
lloydg | 2:2033db202017 | 109 | //end = timer.read_us(); |
lloydg | 2:2033db202017 | 110 | for(pointx=0; pointx<320; pointx++) { |
lloydg | 2:2033db202017 | 111 | TFT.pixel(pointx,buff[pointx], Green); |
lloydg | 2:2033db202017 | 112 | } |
lloydg | 2:2033db202017 | 113 | led3 = !led3; |
lloydg | 2:2033db202017 | 114 | TFT.locate(0,0); |
lloydg | 2:2033db202017 | 115 | //end = timer.read_us(); |
lloydg | 2:2033db202017 | 116 | //printf("%d us", end - begin); // 1 read< 1uS |
lloydg | 2:2033db202017 | 117 | |
lloydg | 2:2033db202017 | 118 | break; |
lloydg | 2:2033db202017 | 119 | default: |
lloydg | 2:2033db202017 | 120 | TFT.newcls(); |
lloydg | 2:2033db202017 | 121 | TFT.locate(0,100); |
lloydg | 2:2033db202017 | 122 | printf(" nothing to see \n"); |
lloydg | 2:2033db202017 | 123 | break; |
lloydg | 2:2033db202017 | 124 | } |
lloydg | 2:2033db202017 | 125 | wait(1); |
lloydg | 2:2033db202017 | 126 | } |
lloydg | 2:2033db202017 | 127 | |
lloydg | 2:2033db202017 | 128 | } |