Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DipCortex-USB-EEProm by
main.cpp@3:5fffa4cb4ca1, 2014-02-23 (annotated)
- Committer:
- SolderSplashLabs
- Date:
- Sun Feb 23 22:53:22 2014 +0000
- Revision:
- 3:5fffa4cb4ca1
- Parent:
- 2:ec470dd97c6e
DipCortex example showing USB CDC and reading/writing to the on chip EEprom
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 0:8c4eea221dcf | 1 | /** |
yihui | 0:8c4eea221dcf | 2 | * USB to UART Bridge |
yihui | 0:8c4eea221dcf | 3 | */ |
yihui | 0:8c4eea221dcf | 4 | |
yihui | 0:8c4eea221dcf | 5 | #include "mbed.h" |
yihui | 0:8c4eea221dcf | 6 | #include "USBSerial.h" |
SolderSplashLabs | 3:5fffa4cb4ca1 | 7 | #include "DipCortex-EEprom.h" |
yihui | 0:8c4eea221dcf | 8 | |
SolderSplashLabs | 2:ec470dd97c6e | 9 | // Serial TX Pin19, Serial RX Pin20 |
SolderSplashLabs | 2:ec470dd97c6e | 10 | // Using port and pin names as the mbed definitions pin defs for the M0 are incorrect |
SolderSplashLabs | 2:ec470dd97c6e | 11 | Serial uart(P1_13, P1_14); |
yihui | 0:8c4eea221dcf | 12 | USBSerial pc; |
yihui | 0:8c4eea221dcf | 13 | |
yihui | 0:8c4eea221dcf | 14 | // Called by ISR |
yihui | 0:8c4eea221dcf | 15 | void settingsChanged(int baud, int bits, int parity, int stop) |
yihui | 0:8c4eea221dcf | 16 | { |
yihui | 0:8c4eea221dcf | 17 | const Serial::Parity parityTable[] = {Serial::None, Serial::Odd, Serial::Even, Serial::Forced0, Serial::Forced1}; |
yihui | 0:8c4eea221dcf | 18 | |
yihui | 0:8c4eea221dcf | 19 | if (stop != 2) { |
yihui | 0:8c4eea221dcf | 20 | stop = 1; // stop bit(s) = 1 or 1.5 |
yihui | 0:8c4eea221dcf | 21 | } |
yihui | 0:8c4eea221dcf | 22 | |
yihui | 0:8c4eea221dcf | 23 | uart.baud(baud); |
yihui | 0:8c4eea221dcf | 24 | uart.format(bits, parityTable[parity], stop); |
yihui | 0:8c4eea221dcf | 25 | } |
yihui | 0:8c4eea221dcf | 26 | |
yihui | 0:8c4eea221dcf | 27 | int main() |
yihui | 0:8c4eea221dcf | 28 | { |
SolderSplashLabs | 3:5fffa4cb4ca1 | 29 | volatile char charIn; |
SolderSplashLabs | 3:5fffa4cb4ca1 | 30 | char tempBuf[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
SolderSplashLabs | 3:5fffa4cb4ca1 | 31 | int i = 0; |
SolderSplashLabs | 3:5fffa4cb4ca1 | 32 | |
SolderSplashLabs | 3:5fffa4cb4ca1 | 33 | IAP_Init(); |
yihui | 0:8c4eea221dcf | 34 | pc.attach(settingsChanged); |
yihui | 0:8c4eea221dcf | 35 | |
SolderSplashLabs | 3:5fffa4cb4ca1 | 36 | // wait for a key press |
SolderSplashLabs | 3:5fffa4cb4ca1 | 37 | charIn = pc.getc(); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 38 | |
SolderSplashLabs | 3:5fffa4cb4ca1 | 39 | while (1) |
SolderSplashLabs | 3:5fffa4cb4ca1 | 40 | { |
SolderSplashLabs | 3:5fffa4cb4ca1 | 41 | pc.printf("Press a key to start\r\n"); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 42 | charIn = pc.getc(); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 43 | |
SolderSplashLabs | 3:5fffa4cb4ca1 | 44 | // Test read |
SolderSplashLabs | 3:5fffa4cb4ca1 | 45 | tempBuf[0] = 0; |
SolderSplashLabs | 3:5fffa4cb4ca1 | 46 | IAP_Eeprom_Read(1, (uint8_t *)&tempBuf, 15); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 47 | pc.printf("EEprom Read : %s\r\n", &tempBuf[0]); |
yihui | 0:8c4eea221dcf | 48 | |
SolderSplashLabs | 3:5fffa4cb4ca1 | 49 | // Write |
SolderSplashLabs | 3:5fffa4cb4ca1 | 50 | sprintf( &tempBuf[0], "Testing %i", i ); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 51 | IAP_Eeprom_Write(1, (uint8_t *)&tempBuf, 15); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 52 | pc.printf("EEprom Writen : %s\r\n", &tempBuf[0]); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 53 | |
SolderSplashLabs | 3:5fffa4cb4ca1 | 54 | tempBuf[0] = 0; |
SolderSplashLabs | 3:5fffa4cb4ca1 | 55 | pc.printf("Press a key to read back\r\n"); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 56 | charIn = pc.getc(); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 57 | |
SolderSplashLabs | 3:5fffa4cb4ca1 | 58 | // Read Back |
SolderSplashLabs | 3:5fffa4cb4ca1 | 59 | tempBuf[0] = 0; |
SolderSplashLabs | 3:5fffa4cb4ca1 | 60 | IAP_Eeprom_Read(1, (uint8_t *)&tempBuf, 15); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 61 | pc.printf("EEprom Read : %s\r\n", &tempBuf[0]); |
SolderSplashLabs | 3:5fffa4cb4ca1 | 62 | |
SolderSplashLabs | 3:5fffa4cb4ca1 | 63 | i++; |
yihui | 0:8c4eea221dcf | 64 | } |
yihui | 0:8c4eea221dcf | 65 | } |