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.
Dependencies: MODSERIAL USBDevice_for_Rev_C_HW mbed
Fork of mbed_sv_firmware_with_init by
Diff: main.cpp
- Revision:
- 6:2941452a0e6d
- Parent:
- 5:e77529f7ede3
- Child:
- 8:3313aa7f9082
diff -r e77529f7ede3 -r 2941452a0e6d main.cpp --- a/main.cpp Wed Jan 21 01:10:59 2015 +0000 +++ b/main.cpp Thu Jan 22 01:42:02 2015 +0000 @@ -26,6 +26,7 @@ // I2C addresses #define PROX (0x29 << 1) // default I2C address of VL6180X, shift into upper 7 bits #define EEPROM (0xA0) // default I2C address of EEPROM, already shifted +#define I2CRATE 400000 // I2C speed // UART-RFID baud rate #define RFIDBAUD 115200 // RFID-FE board default rate = 115.2Kbps @@ -48,7 +49,7 @@ // buffers & variables uint8_t gpio_values = 0x00; // register to read GPIO values -uint8_t cdc_buffer_rx[32]; // buffers for cdc (USB-Serial port on PC) +uint8_t cdc_buffer_rx[32] = {0xBB, 0x00, 0x03, 0x00, 0x01, 0x02, 0x7E, 0x2E, 0xC9}; // buffers for cdc (USB-Serial port on PC) uint8_t cdc_buffer_tx[32]; uint8_t uart_buffer_rx[32]; // buffers for uart (RFID-FE board) uint8_t uart_buffer_tx[32]; @@ -76,7 +77,7 @@ rfid_rst = 0; // ... taking RFID out of reset // Prox & EEPROM - i2c.frequency(400000); // I2C speed = 400Kbps + i2c.frequency(I2CRATE); // I2C speed = 400Kbps prox_int.mode(PullUp); // pull up proximity sensor interrupt at MCU // LEDs // Cycle through the LEDs. @@ -87,9 +88,6 @@ wait(0.5); led_com.write(LEDOFF); - - - return 0; } @@ -112,6 +110,7 @@ led_err.write(LEDON); return ERR_UART_NOT_WRITEABLE; // if no space in uart, return error } + uart.putc(uart_buffer_tx[i]); // send uart message if (uart_buffer_tx[i] == 0x7E) // check for rfid end mark in outbound message @@ -131,13 +130,11 @@ } end_mark = FALSE; - //wait(0.5); // debug while(!uart.readable()); // wait for data from rfid crcCount = sizeof(uart_buffer_rx); // use rx buffer size to start for (i = 0; i < sizeof(uart_buffer_rx); i++) { uart_buffer_rx[i] = uart.getc(); // read a character -// cdc.printf("%d, 0x%X\n\r", i, uart_buffer_rx[i]); // debug if (uart_buffer_rx[i] == 0x7E) // check for rfid end mark in inbound message { @@ -182,20 +179,28 @@ // GPIO messages = 0xDD, r/w, value, 0x7E, 0xXX, 0xXX - last two are fillers where CRC goes for RFID int gpio_rd() { - gpio_buffer[2] = (led_err.read() && 0x01); // read all of the GPIO pins and store in a single byte - gpio_buffer[2] |= ((led_com.read() << 1) && 0x02); - gpio_buffer[2] |= ((rfid_int.read() << 2) && 0x04); - gpio_buffer[2] |= ((rfid_isp.read() << 3) && 0x08); - gpio_buffer[2] |= ((rfid_rst.read() << 4) && 0x10); - gpio_buffer[2] |= ((rfid_pwr.read() << 5) && 0x20); - gpio_buffer[2] |= ((rfid_hot.read() << 6) && 0x40); - gpio_buffer[2] |= ((prox_int.read() << 7) && 0x80); + led_err.write(LEDON); + led_com.write(LEDON); +rfid_int.write(0); +rfid_isp.write(0); +cdc.putc( led_err.read());// && 0x01); // read all of the GPIO pins and store in a single byte +cdc.putc( led_com.read());// << 1) && 0x02); +cdc.putc( rfid_int.read());// << 2) && 0x04); +cdc.putc( rfid_isp.read());// << 3) && 0x08); + return ERR_NONE; } int gpio_wr() { + cdc.printf("debug"); + cdc.putc(gpio_buffer[2] && 0x01); + cdc.putc(gpio_buffer[2] && 0x02); + cdc.putc(gpio_buffer[2] && 0x04); + cdc.putc(gpio_buffer[2] && 0x08); + cdc.putc(gpio_buffer[2] && 0x10); + cdc.putc(gpio_buffer[2] && 0x20); led_err.write(gpio_buffer[2] && 0x01); // any bit set will write a 0 led_com.write(gpio_buffer[2] && 0x02); // any bit set will write a 0 rfid_int.write(gpio_buffer[2] && 0x04); // any bit set will write a 0 @@ -237,13 +242,12 @@ int main() { // initialize everything + + wait(2.0); - wait(2.0); // debug - gives some time to start terminal program and open COM port - init_periph(); - cdc.printf("Starting...\n\r"); // debug - + while(1) { led_com.write(LEDOFF); // turn off communication LED @@ -251,12 +255,9 @@ led_com.write(LEDON); // Message received - turn on LED bool end_mark = FALSE; uint8_t crcCount = sizeof(cdc_buffer_rx); // use tx buffer size to start - //cdc.printf("\n\rCDC Input: "); // debug for (i = 0; i < sizeof(cdc_buffer_rx); i++) { cdc_buffer_rx[i] = cdc.getc(); // read data from USB side - - //cdc.printf("%X, ",cdc_buffer_rx[i]); // debug if (cdc_buffer_rx[i] == 0x7E) // check for rfid end mark in outbound message { @@ -285,8 +286,6 @@ cdc_buffer_tx[i] = uart_buffer_rx[i]; // copy RFID response back to USB buffer } - //cdc.printf("\n\rRFID Response: "); // debug - for (i = 0; i < sizeof(cdc_buffer_tx); i++) { cdc.putc(cdc_buffer_tx[i]); // send message back to PC @@ -339,20 +338,20 @@ break; case 0xDD: // GPIO (LEDs and RFID-FE control) - //GPIO messages = 0xDD, r/w, value, 0x7E, 0xXX, 0xXX - last two are fillers where CRC goes for RFID + //GPIO messages = 0xDD, r/w#, value, 0x7E, 0xXX, 0xXX - last two are fillers where CRC goes for RFID for (i = 0; i < sizeof(cdc_buffer_rx); i++) { gpio_buffer[i] = cdc_buffer_rx[i]; // copy USB message to buffer for I2C } - if (gpio_buffer[1] == 1) // I2C read = 1 + if (gpio_buffer[1] == 1) // GPIO read = 1 status = gpio_rd(); // read the requested data - else if (gpio_buffer[1] == 0) // I2C write = 0 - status = gpio_wr(); // send buffer to proximity sensor and get response + else if (gpio_buffer[1] == 0) // GPIO write = 0 + status = gpio_wr(); // send GPIO pin data for (i = 0; i < sizeof(cdc_buffer_tx); i++) { - cdc_buffer_tx[i] = gpio_buffer[i]; // copy prox response back to USB buffer + cdc_buffer_tx[i] = gpio_buffer[i]; // copy GPIO response back to USB buffer } for (i = 0; i < sizeof(cdc_buffer_tx); i++)