Sog Yang
/
mbed_SPIS_multiByte_example_SOG
Sog update version
Fork of mbed_SPIS_multiByte_example by
Diff: main.cpp
- Revision:
- 5:6a1155885fc9
- Parent:
- 4:8e796b751cd3
- Child:
- 6:bce37a45b9cb
--- a/main.cpp Thu Jun 01 07:59:21 2017 +0000 +++ b/main.cpp Tue Jun 13 04:34:01 2017 +0000 @@ -26,23 +26,65 @@ //} #include "mbed.h" +#include "SPISlave_multiByte.h" -#include "SPISlave_multiByte.h" -SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel +//SPISlave_multiByte device(A1, A2, A3, p3); // mosi, miso, sclk, ssel +SPISlave_multiByte device(p15, p9, p11, p29); // mosi, miso, sclk, ssel Serial uart(USBTX, USBRX); +DigitalOut myled(LED1); -#define TXRX_LENGTH 16 //max is 16 + +inline void hexview(const char *buffer, unsigned int size) { + char byte[50]; + char text[20]; + bool big = false; + int i; + for(i = 0; i < size; ++i) { + if((i&0xF) == 0x0) { + if(big) + printf("%04X: %-49s: %-20s\n", (i&~0xF), byte, text); + big = false; + byte[0] = '\0'; + text[0] = '\0'; + } else if((i&0xF) == 0x8) { + big = true; + byte[(i&0xF) * 3] = ' '; + text[(i&0xF)] = ' '; + } + unsigned char value = buffer[i]; + text[(i&0xF) + 0 + big] = (value < 0x20 || value > 0x7F)? '.': value; + text[(i&0xF) + 1 + big] = '\0'; + value = (buffer[i] &0xF0) >> 4; + byte[(i&0xF) * 3 + 0 + big] = (value < 0xA)? (value + 0x30): (value + 0x37); + value = (buffer[i] &0x0F); + byte[(i&0xF) * 3 + 1 + big] = (value < 0xA)? (value + 0x30): (value + 0x37); + byte[(i&0xF) * 3 + 2 + big] = ' '; + byte[(i&0xF) * 3 + 3 + big] = '\0'; + } + if(byte[0]) { + uart.printf("%04X: %-49s: %-20s\n", (i&~0xF), byte, text); + } + uart.printf("\n"); +} + int main() { uart.printf("START!"); - device.format(8,1); - device.frequency(8000000); + device.format(8,0); + myled = 1; - device.reply((uint8_t*)"xyz", TXRX_LENGTH); while(1) { - if(device.receive(TXRX_LENGTH)) { - int ret = device.read(); // Read byte from master - uart.printf("ret = %s ", ret); - - } + + uart.printf("Add: %p \r\n", device.read()); + uart.printf("%c \r\n", device.read()); + + while (!device.readable()) { + __WFE(); + } + hexview((const char *)0x200032D0, 224); + //hexview((const char *)ptr, 224); + //uart.printf("%c\r\n",m_rx_buf[3]); + + myled = !myled; + wait_ms(200); } } \ No newline at end of file