Data sample and LCD plot
Dependencies: BSP_DISCO_F746NG LCD_DISCO_F746NG SDRAM_DISCO_F746NG mbed
main.cpp
- Committer:
- tapiov
- Date:
- 2018-02-10
- Revision:
- 0:b3e6088c873f
- Child:
- 1:c3c61d08f31b
File content as of revision 0:b3e6088c873f:
#include "mbed.h" #include <string.h> #include "LCD_DISCO_F746NG.h" #include "SDRAM_DISCO_F746NG.h" LCD_DISCO_F746NG lcd; SDRAM_DISCO_F746NG sdram; #define BUFFER_SIZE ((uint32_t)0x0001) #define WRITE_READ_ADDR ((uint32_t)0x0800) void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Offset); uint8_t CompareBuffer(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength); Ticker ms_tick; uint32_t idx; uint32_t WRITE_READ_ADDR; (()0x0800) void onTimingEventTicker(void) { // this code will run every timing event uint32_t result; uint32_t y_coord; AnalogIn ain(A0); result = (0x0000 << 16) | ain.read_u16(); // Fill the write buffer FillBuffer(WriteBuffer, BUFFER_SIZE, result); // Write buffer sdram.WriteData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR + idx, WriteBuffer, BUFFER_SIZE); idx++; } uint32_t PlotData(void) { // this code will run every timing event uint32_t result; uint32_t y_coord; AnalogIn ain(A0); if (x_coord == 0) { lcd.Clear(LCD_COLOR_BLUE); } result = (0x0000 << 16) | ain.read_u16(); y_coord=(272.0*result)/16384.0; if (x_coord < 480) { x_coord++; } else { x_coord=0; } //snprintf(my_str, 50,"Result = %f\0", result/4096.0); //snprintf(my_str, 50,"Loops = %i\0", loops); //lcd.DisplayStringAt(0, LINE(5), (uint8_t *)my_str, CENTER_MODE); // Plot loops,y_coord lcd.DrawHLine(loops,y_coord,1); } int main() { uint32_t WriteBuffer[BUFFER_SIZE]; uint32_t ReadBuffer[BUFFER_SIZE]; FMC_SDRAM_CommandTypeDef SDRAMCommandStructure; // # of samples idx=0; // turn on 100 us interrupt ms_tick.attach_us(onTimingEventTicker,100); lcd.Clear(LCD_COLOR_BLUE); lcd.SetBackColor(LCD_COLOR_BLUE); lcd.SetTextColor(LCD_COLOR_WHITE); // Issue self-refresh command to SDRAM device SDRAMCommandStructure.CommandMode=FMC_SDRAM_CMD_SELFREFRESH_MODE; SDRAMCommandStructure.CommandTarget=FMC_SDRAM_CMD_TARGET_BANK2; SDRAMCommandStructure.AutoRefreshNumber=1; SDRAMCommandStructure.ModeRegisterDefinition = 0; while(1) { // Measure 19200 values (1.920 s time) while(idx<19200) { // Wait while the data is collected } // Read back data from the SDRAM memory sdram.ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR + idx, ReadBuffer, BUFFER_SIZE); pc.printf("\nRead data DONE\n"); // Read back data from the SDRAM memory // sdram.ReadData(SDRAM_DEVICE_ADDR + WRITE_READ_ADDR, ReadBuffer, BUFFER_SIZE); // pc.printf("\nRead data DONE\n"); // Checking data integrity // if (CompareBuffer(WriteBuffer, ReadBuffer, BUFFER_SIZE) != 0) // { // led1 = !led1; // pc.printf("Write/Read buffers are different\n"); // } // else // { // led1 = !led1; // pc.printf("Write/Read buffers are identical\n"); // } // wait(1); } } /** * @brief Fills buffer with user predefined data. * @param pBuffer: pointer on the buffer to fill * @param BufferLength: size of the buffer to fill * @param Value: first value to fill on the buffer * @retval None */ void FillBuffer(uint32_t *pBuffer, uint32_t BufferLength, uint32_t Value) { uint32_t tmpIndex = 0; /* Put in global buffer different values */ for (tmpIndex = 0; tmpIndex < BufferLength; tmpIndex++ ) { pBuffer[tmpIndex] = tmpIndex + Value; } } /** * @brief Compares two buffers. * @param pBuffer1, pBuffer2: buffers to be compared. * @param BufferLength: buffer's length * @retval 0: pBuffer2 identical to pBuffer1 * 1: pBuffer2 differs from pBuffer1 */ uint8_t CompareBuffer(uint32_t* pBuffer1, uint32_t* pBuffer2, uint16_t BufferLength) { while (BufferLength--) { if (*pBuffer1 != *pBuffer2) { return 1; } pBuffer1++; pBuffer2++; } return 0; }