Wim Huiskamp
/
SC16IS750_Test
Testsoftware for SC16IS750
Diff: main.cpp
- Revision:
- 1:f0d3984f2586
- Parent:
- 0:d83a90125711
- Child:
- 2:8aba07490dce
diff -r d83a90125711 -r f0d3984f2586 main.cpp --- a/main.cpp Wed Jan 22 16:40:03 2014 +0000 +++ b/main.cpp Sun Feb 09 14:58:33 2014 +0000 @@ -4,22 +4,166 @@ //SPI Version SPI spi(PTD2, PTD3, PTD1); //MOSI, MISO, SCK //DigitalOut CS(PTD0); //CS -SC16IS750_SPI serial_spi(&spi, PTD0); +SC16IS750_SPI serial_bridge(&spi, PTD0); //I2C Version -I2C i2c(PTE0, PTE1); //SDA, SCL -SC16IS750_I2C serial_i2c(&i2c, DEFAULT_SC16IS750_ADDR); +//I2C i2c(PTE0, PTE1); //SDA, SCL +//SC16IS750_I2C serial_bridge(&i2c, DEFAULT_SC16IS750_ADDR); DigitalOut myled1(LED_RED); -DigitalOut myled2(LED_GREEN); -//DigitalOut myled3(LED_BLUE); //same as PTD1 (SCK) +//DigitalOut myled2(LED_GREEN); +//DigitalOut myled3(LED_BLUE); // Same as PTD1 (SCK) +DigitalOut heartbeatLED(LED_GREEN); Serial pc(USBTX,USBRX); +void show_menu() { + pc.printf("0: Exit\n\r"); + pc.printf("1: Show Menu\n\r"); + pc.printf("2: Init\n\r"); + pc.printf("3: IO Out\n\r"); + pc.printf("4: Echo Text\n\r"); + + #if(0) + + pc.printf("5: \n\r"); + pc.printf("6: \n\r"); + pc.printf("7: \n\r"); + pc.printf("8: \n\r"); + pc.printf("9: \n\r"); + pc.printf("A: \n\r"); + pc.printf("B: \n\r"); + pc.printf("C: \n\r"); + pc.printf("D: \n\r"); + pc.printf("P: \n\r"); +#endif + pc.printf("\n\r"); +} + +// Variables for Heartbeat and Status monitoring +Ticker heartbeat; +bool heartbeatflag=false; + +// Local functions +void clear_screen() { +//ANSI Terminal Commands + pc.printf("\x1B[2J"); + pc.printf("\x1B[H"); +} + + +// Heartbeat monitor +void pulse() { + heartbeatLED = !heartbeatLED; +} + +void heartbeat_start() { + heartbeat.attach(&pulse, 0.5); +} + +void heartbeat_stop() { + heartbeat.detach(); +} + + int main() { - pc.printf("\nHello World!\n"); + bool running=true; + char command; + int i=0; + + pc.printf("\nHello World!\n\r"); + + heartbeat_start(); + + myled1 = 1; // LED Off + + // We need to enable flow control or we overflow buffers and + // lose data when used with the WiFly. Note that flow control + // needs to be enabled on the WiFly for this to work but it's + // possible to do that with flow control enabled here but not there. +// serial_bridge.set_flow_control(SC16IS750::RTSCTS); + + serial_bridge.ioSetDirection(0xFF); // All outputs + serial_bridge.ioSetState(0x00); // All On + + show_menu(); + + while(running) { - myled1 = 1; // LED Off + if(pc.readable()) { + command = pc.getc(); + pc.printf("command= %c \n\r", command); + + switch (command) { + case '0' : + pc.printf("Done\n\r"); + running = false; + break; + + case '1' : + show_menu(); + break; + + case '2' : + pc.printf("Init\n\r"); + serial_bridge._init(); + break; + + case '3' : + pc.printf("IO Out\n\r"); + + i=0; + while (!pc.readable()) { + serial_bridge.ioSetState(~i); + serial_bridge.ioGetState() ; //test + wait(0.5); + pc.putc('*'); + i=(i+1) & 0xFF; + } + + pc.getc(); + pc.printf("IO Out Done\n\r"); + break; + + case '4' : + pc.printf("Echo Text, Enter '$' to quit...\n\r"); + + char ch; + bool running_test=true; + + while (running_test) { + // From SPI/I2C to serial + while (running_test && pc.readable()) { + ch = pc.getc(); + running_test = (ch != '$'); + serial_bridge.putc(ch); + } + + // From Serial to SPI/I2C + while (running_test && serial_bridge.readable()) { + ch = serial_bridge.getc(); + running_test = (ch != '$'); + pc.putc(ch); + } + + } + + pc.printf("\n\rEcho Text Done\n\r"); + break; + + default : + break; + + } //switch + } //if + } //while + + + + +#if(0) + + // CS = 1; spi.format(8, 0); @@ -27,17 +171,9 @@ // spi.frequency(500000); spi.frequency(1000000); // spi.frequency(1500000); - - while(1) { -// serial_spi.writeRegister(SC16IS750::IODIR, 0x81); // direct call to new method - - serial_spi.ioSetState(0x00); // indirect call to new method -// wait(0.5); - pc.putc('*'); - } -#if(0) + while(1) { CS=0; spi.write(0xAA);