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.
Diff: main.cpp
- Revision:
- 17:54a003ac9610
- Parent:
- 16:fbe18dbc2fb7
- Child:
- 18:452b5da21cfd
--- a/main.cpp Tue Jul 16 20:47:21 2013 +0000 +++ b/main.cpp Wed Jul 17 20:47:41 2013 +0000 @@ -1,11 +1,11 @@ -//This main funtion mainly implements a mode transfer. -//When mcu resets, it's in MODE_IDLE. Then depends on the keyboard input, the +//This main funtion implements a mode transfer. +//When mcu resets, it's in MODE_IDLE. Then depends on the keyboard input(1 to 7), the //mode switches to transition modes such as //MODE_CHAxPHA, which is for phase input of channel x, or //MODE_CHAxAMP, which is for attenuation input of channel x, or //MODE_DISPLAY, which is for displaying the current parameters, or //MODE_HELP, which is for displaying the help infomation, or -//MODE_SEND, which is for sending the bit stream through the SPI bus. +//MODE_SEND, which is for sending the bit stream through the SPI bus by MOSI and read the data back from MISO. //After each transition mode completes, mcu returns to MODE_IDLE to wait for another user input. @@ -15,9 +15,9 @@ #include "handlers.h" //#define DEBUG -Serial pc(USBTX, USBRX); +Serial pc(USBTX, USBRX); // serial io SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk -DigitalOut cs(PTD0); +DigitalOut cs(PTD0); //SPI chip select char recv; char temp; @@ -41,10 +41,11 @@ int main() { - pc.baud(19200); //config buad rate. Note: 115200 seems too high for the current board - cs = 1; //spi config - spi.format(8,0); // 16 bit frame is not working, so need to send twice 8 bit frame - spi.frequency(1000000); + pc.baud(19200); //config buad rate. Note: 115200 seems too high for the current board + cs = 1; //spi config + spi.format(8,0); //16 bit frame is not working, so need to send twice 8 bit frame + //For more info about format, see http://mbed.org/forum/bugs-suggestions/topic/4419/?page=1#comment-22056 + spi.frequency(1000000); state = MODE_IDLE; line_buf[3] = 0; @@ -64,7 +65,7 @@ pc.printf("%s", main_menu); recv = pc.getc(); mode_idle_handler(&state, recv); //change state based on recv input - //pc.printf("%d", state); + break; case MODE_CHA1PHA: @@ -251,7 +252,7 @@ spi_first_byte_s = (cha2_amp << 4) | (cha2_pha); spi_second_byte_s = (cha1_amp << 4) | (cha1_pha); - cs = 0; // start sending, send and recond the response(send and loopback in this case) + cs = 0; //SPI start sending, send and recond the response spi_first_byte_r = spi.write(spi_first_byte_s); spi_second_byte_r = spi.write(spi_second_byte_s); cs = 1; @@ -281,13 +282,13 @@ pc.printf("\n\nParameters sent OK\n\n\n\n"); - //output the previous parameters: + //Output the previous parameters: pc.printf("Now displaying the previous parameters\n"); pc.printf("\nPrevious phase shift for RF out1 is %d degrees\n", (spi_second_byte_r&0x07)*-7); pc.printf("Previous attentuation for RF out1 is %.1f dB\n", (spi_second_byte_r>>4)*5.0/10.0); pc.printf("Previous phase shift for RF out2 is %d degrees\n", (spi_first_byte_r&0x07)*-7); pc.printf("Previous attentuation for RF out2 is %.1f dB\n", (spi_first_byte_r>>4)*5.0/10.0); - //spi bit stream for previous parameters + //SPI bit stream for previous parameters pc.printf("\nSPI bit stream received:\n"); pc.printf("%s", bit_index); for(i=0; i<=7; i++)