Data sample and LCD plot

Dependencies:   BSP_DISCO_F746NG LCD_DISCO_F746NG SDRAM_DISCO_F746NG mbed

Committer:
tapiov
Date:
Sat Feb 10 20:19:36 2018 +0000
Revision:
0:b3e6088c873f
Child:
1:c3c61d08f31b
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tapiov 0:b3e6088c873f 1 #include "mbed.h"
tapiov 0:b3e6088c873f 2 #include <string.h>
tapiov 0:b3e6088c873f 3 #include "LCD_DISCO_F746NG.h"
tapiov 0:b3e6088c873f 4 #include "SDRAM_DISCO_F746NG.h"
tapiov 0:b3e6088c873f 5
tapiov 0:b3e6088c873f 6 LCD_DISCO_F746NG lcd;
tapiov 0:b3e6088c873f 7 SDRAM_DISCO_F746NG sdram;
tapiov 0:b3e6088c873f 8
tapiov 0:b3e6088c873f 9 #define BUFFER_SIZE ((uint32_t)0x0001)
tapiov 0:b3e6088c873f 10 #define WRITE_READ_ADDR ((uint32_t)0x0800)
tapiov 0:b3e6088c873f 11
tapiov 0:b3e6088c873f 12 void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Offset);
tapiov 0:b3e6088c873f 13 uint8_t CompareBuffer(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength);
tapiov 0:b3e6088c873f 14
tapiov 0:b3e6088c873f 15 Ticker ms_tick;
tapiov 0:b3e6088c873f 16 uint32_t idx;
tapiov 0:b3e6088c873f 17 uint32_t WRITE_READ_ADDR; (()0x0800)
tapiov 0:b3e6088c873f 18
tapiov 0:b3e6088c873f 19 void onTimingEventTicker(void)
tapiov 0:b3e6088c873f 20 {
tapiov 0:b3e6088c873f 21 // this code will run every timing event
tapiov 0:b3e6088c873f 22 uint32_t result;
tapiov 0:b3e6088c873f 23 uint32_t y_coord;
tapiov 0:b3e6088c873f 24
tapiov 0:b3e6088c873f 25 AnalogIn ain(A0);
tapiov 0:b3e6088c873f 26
tapiov 0:b3e6088c873f 27 result = (0x0000 << 16) | ain.read_u16();
tapiov 0:b3e6088c873f 28
tapiov 0:b3e6088c873f 29 // Fill the write buffer
tapiov 0:b3e6088c873f 30 FillBuffer(WriteBuffer, BUFFER_SIZE, result);
tapiov 0:b3e6088c873f 31
tapiov 0:b3e6088c873f 32 // Write buffer
tapiov 0:b3e6088c873f 33 sdram.WriteData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR + idx, WriteBuffer, BUFFER_SIZE);
tapiov 0:b3e6088c873f 34
tapiov 0:b3e6088c873f 35 idx++;
tapiov 0:b3e6088c873f 36 }
tapiov 0:b3e6088c873f 37
tapiov 0:b3e6088c873f 38 uint32_t PlotData(void)
tapiov 0:b3e6088c873f 39 {
tapiov 0:b3e6088c873f 40 // this code will run every timing event
tapiov 0:b3e6088c873f 41 uint32_t result;
tapiov 0:b3e6088c873f 42 uint32_t y_coord;
tapiov 0:b3e6088c873f 43
tapiov 0:b3e6088c873f 44 AnalogIn ain(A0);
tapiov 0:b3e6088c873f 45
tapiov 0:b3e6088c873f 46 if (x_coord == 0) { lcd.Clear(LCD_COLOR_BLUE); }
tapiov 0:b3e6088c873f 47
tapiov 0:b3e6088c873f 48 result = (0x0000 << 16) | ain.read_u16();
tapiov 0:b3e6088c873f 49
tapiov 0:b3e6088c873f 50 y_coord=(272.0*result)/16384.0;
tapiov 0:b3e6088c873f 51
tapiov 0:b3e6088c873f 52
tapiov 0:b3e6088c873f 53 if (x_coord < 480) { x_coord++; } else { x_coord=0; }
tapiov 0:b3e6088c873f 54
tapiov 0:b3e6088c873f 55 //snprintf(my_str, 50,"Result = %f\0", result/4096.0);
tapiov 0:b3e6088c873f 56 //snprintf(my_str, 50,"Loops = %i\0", loops);
tapiov 0:b3e6088c873f 57
tapiov 0:b3e6088c873f 58 //lcd.DisplayStringAt(0, LINE(5), (uint8_t *)my_str, CENTER_MODE);
tapiov 0:b3e6088c873f 59
tapiov 0:b3e6088c873f 60 // Plot loops,y_coord
tapiov 0:b3e6088c873f 61 lcd.DrawHLine(loops,y_coord,1);
tapiov 0:b3e6088c873f 62
tapiov 0:b3e6088c873f 63 }
tapiov 0:b3e6088c873f 64
tapiov 0:b3e6088c873f 65 int main() {
tapiov 0:b3e6088c873f 66
tapiov 0:b3e6088c873f 67 uint32_t WriteBuffer[BUFFER_SIZE];
tapiov 0:b3e6088c873f 68 uint32_t ReadBuffer[BUFFER_SIZE];
tapiov 0:b3e6088c873f 69 FMC_SDRAM_CommandTypeDef SDRAMCommandStructure;
tapiov 0:b3e6088c873f 70
tapiov 0:b3e6088c873f 71 // # of samples
tapiov 0:b3e6088c873f 72 idx=0;
tapiov 0:b3e6088c873f 73
tapiov 0:b3e6088c873f 74 // turn on 100 us interrupt
tapiov 0:b3e6088c873f 75 ms_tick.attach_us(onTimingEventTicker,100);
tapiov 0:b3e6088c873f 76
tapiov 0:b3e6088c873f 77 lcd.Clear(LCD_COLOR_BLUE);
tapiov 0:b3e6088c873f 78 lcd.SetBackColor(LCD_COLOR_BLUE);
tapiov 0:b3e6088c873f 79 lcd.SetTextColor(LCD_COLOR_WHITE);
tapiov 0:b3e6088c873f 80
tapiov 0:b3e6088c873f 81 // Issue self-refresh command to SDRAM device
tapiov 0:b3e6088c873f 82 SDRAMCommandStructure.CommandMode=FMC_SDRAM_CMD_SELFREFRESH_MODE;
tapiov 0:b3e6088c873f 83 SDRAMCommandStructure.CommandTarget=FMC_SDRAM_CMD_TARGET_BANK2;
tapiov 0:b3e6088c873f 84 SDRAMCommandStructure.AutoRefreshNumber=1;
tapiov 0:b3e6088c873f 85 SDRAMCommandStructure.ModeRegisterDefinition = 0;
tapiov 0:b3e6088c873f 86
tapiov 0:b3e6088c873f 87 while(1) {
tapiov 0:b3e6088c873f 88
tapiov 0:b3e6088c873f 89 // Measure 19200 values (1.920 s time)
tapiov 0:b3e6088c873f 90 while(idx<19200) {
tapiov 0:b3e6088c873f 91 // Wait while the data is collected
tapiov 0:b3e6088c873f 92 }
tapiov 0:b3e6088c873f 93
tapiov 0:b3e6088c873f 94 // Read back data from the SDRAM memory
tapiov 0:b3e6088c873f 95 sdram.ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR + idx, ReadBuffer, BUFFER_SIZE);
tapiov 0:b3e6088c873f 96 pc.printf("\nRead data DONE\n");
tapiov 0:b3e6088c873f 97
tapiov 0:b3e6088c873f 98
tapiov 0:b3e6088c873f 99 // Read back data from the SDRAM memory
tapiov 0:b3e6088c873f 100 // sdram.ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, ReadBuffer, BUFFER_SIZE);
tapiov 0:b3e6088c873f 101 // pc.printf("\nRead data DONE\n");
tapiov 0:b3e6088c873f 102
tapiov 0:b3e6088c873f 103 // Checking data integrity
tapiov 0:b3e6088c873f 104 // if (CompareBuffer(WriteBuffer, ReadBuffer, BUFFER_SIZE) != 0)
tapiov 0:b3e6088c873f 105 // {
tapiov 0:b3e6088c873f 106 // led1 = !led1;
tapiov 0:b3e6088c873f 107 // pc.printf("Write/Read buffers are different\n");
tapiov 0:b3e6088c873f 108 // }
tapiov 0:b3e6088c873f 109 // else
tapiov 0:b3e6088c873f 110 // {
tapiov 0:b3e6088c873f 111 // led1 = !led1;
tapiov 0:b3e6088c873f 112 // pc.printf("Write/Read buffers are identical\n");
tapiov 0:b3e6088c873f 113 // }
tapiov 0:b3e6088c873f 114
tapiov 0:b3e6088c873f 115 // wait(1);
tapiov 0:b3e6088c873f 116
tapiov 0:b3e6088c873f 117 }
tapiov 0:b3e6088c873f 118 }
tapiov 0:b3e6088c873f 119
tapiov 0:b3e6088c873f 120 /**
tapiov 0:b3e6088c873f 121 * @brief Fills buffer with user predefined data.
tapiov 0:b3e6088c873f 122 * @param pBuffer: pointer on the buffer to fill
tapiov 0:b3e6088c873f 123 * @param BufferLength: size of the buffer to fill
tapiov 0:b3e6088c873f 124 * @param Value: first value to fill on the buffer
tapiov 0:b3e6088c873f 125 * @retval None
tapiov 0:b3e6088c873f 126 */
tapiov 0:b3e6088c873f 127 void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Value)
tapiov 0:b3e6088c873f 128 {
tapiov 0:b3e6088c873f 129 uint32_t tmpIndex = 0;
tapiov 0:b3e6088c873f 130
tapiov 0:b3e6088c873f 131 /* Put in global buffer different values */
tapiov 0:b3e6088c873f 132 for (tmpIndex = 0; tmpIndex < BufferLength; tmpIndex++ )
tapiov 0:b3e6088c873f 133 {
tapiov 0:b3e6088c873f 134 pBuffer[tmpIndex] = tmpIndex + Value;
tapiov 0:b3e6088c873f 135 }
tapiov 0:b3e6088c873f 136 }
tapiov 0:b3e6088c873f 137
tapiov 0:b3e6088c873f 138 /**
tapiov 0:b3e6088c873f 139 * @brief Compares two buffers.
tapiov 0:b3e6088c873f 140 * @param pBuffer1, pBuffer2: buffers to be compared.
tapiov 0:b3e6088c873f 141 * @param BufferLength: buffer's length
tapiov 0:b3e6088c873f 142 * @retval 0: pBuffer2 identical to pBuffer1
tapiov 0:b3e6088c873f 143 * 1: pBuffer2 differs from pBuffer1
tapiov 0:b3e6088c873f 144 */
tapiov 0:b3e6088c873f 145 uint8_t CompareBuffer(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength)
tapiov 0:b3e6088c873f 146 {
tapiov 0:b3e6088c873f 147 while (BufferLength--)
tapiov 0:b3e6088c873f 148 {
tapiov 0:b3e6088c873f 149 if (*pBuffer1 != *pBuffer2)
tapiov 0:b3e6088c873f 150 {
tapiov 0:b3e6088c873f 151 return 1;
tapiov 0:b3e6088c873f 152 }
tapiov 0:b3e6088c873f 153
tapiov 0:b3e6088c873f 154 pBuffer1++;
tapiov 0:b3e6088c873f 155 pBuffer2++;
tapiov 0:b3e6088c873f 156 }
tapiov 0:b3e6088c873f 157
tapiov 0:b3e6088c873f 158 return 0;
tapiov 0:b3e6088c873f 159 }