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: UIPEthernet mbed mbed-STM32F103C8T6
Revision 2:e38442f3cb74, committed 2016-08-25
- Comitter:
- hudakz
- Date:
- Thu Aug 25 10:37:39 2016 +0000
- Parent:
- 1:d39ee3c772e8
- Commit message:
- Improved reading serial data.
Changed in this revision
diff -r d39ee3c772e8 -r e38442f3cb74 UIPEthernet.lib --- a/UIPEthernet.lib Sat Apr 11 07:23:02 2015 +0000 +++ b/UIPEthernet.lib Thu Aug 25 10:37:39 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/hudakz/code/UIPEthernet/#d774541a34da +http://mbed.org/users/hudakz/code/UIPEthernet/#10e42359e217
diff -r d39ee3c772e8 -r e38442f3cb74 main.cpp --- a/main.cpp Sat Apr 11 07:23:02 2015 +0000 +++ b/main.cpp Thu Aug 25 10:37:39 2016 +0000 @@ -6,10 +6,10 @@ * * ENC28J60 modul is connected to the mbed board to create a TCP/IP server. * The server is listening for clients at IP address 192.168.1.181, port 10001 (you can adapt it to your needs). - * Binary data received from a client is transmitted to a serial device and + * Binary data received from a client is transmitted over serial device and * in turn data received from the serial device is sent back to the TCP/IP client. * - * How to use: + * How to use the converter: * Compile and save it to your mbed board. * Connect a ENC28J60 module to the mber board according to the pin assignment below. * Connect a serial device to the mbed serial port. Please notice that in case your serial device @@ -29,8 +29,8 @@ #include "UIPEthernet.h" const int BAUD = 115200; // serial bit rate (change to match the speed of the connected serial device) -uint8_t rxBuf[1024]; // serial Rx buffer (reduce the size if you don't use so much data in bulk) -uint8_t txBuf[1024]; // serial Tx buffer (reduce the size if you don't use so much data in bulk) +uint8_t rxBuf[512]; // serial Rx buffer (adjust the size to your needs) +uint8_t txBuf[512]; // serial Tx buffer (adjust the size to your needs) // MAC number must be unique within the connected network. Modify as appropriate. const uint8_t MY_MAC[6] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x06 }; // IP address must be also unique and compatible with your network. Change as appropriate. @@ -44,10 +44,17 @@ #if defined(TARGET_LPC1768) Serial serial(p9, p10); // serial: tx, rx UIPEthernetClass UIPEthernet(p11, p12, p13, p8); // spi: mosi, miso, sck, cs -#elif defined(TARGET_NUCLEO_F103RB) +#elif defined(TARGET_NUCLEO_F103RB) || defined(TARGET_NUCLEO_L152RE) || defined(TARGET_NUCLEO_F030R8) \ + || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_L053R8) \ + || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_F072RB) \ + || defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F070RB) \ + || defined(TARGET_KL25Z ) || defined(TARGET_KL46Z) || defined(TARGET_K64F) || defined(TARGET_KL05Z) \ + || defined(TARGET_K20D50M) || defined(TARGET_K22F) \ + || defined(TARGET_NRF51822) \ + || defined(TARGET_RZ_A1H) Serial serial(PA_2, PA_3); // serial: tx, rx -UIPEthernetClass UIPEthernet(PB_5, PB_4, PB_3, PB_6); // spi: mosi, miso, sck, cs - +UIPEthernetClass UIPEthernet(D11, D12, D13, D10); // spi: mosi, miso, sck, cs +#else // If your board/plaform is not present yet then uncomment // the following three lines and replace TARGET_YOUR_BOARD and other pins as appropriate. @@ -66,7 +73,8 @@ * @retval */ void onSerial(void) { - rxBuf[rxLength++] = serial.getc(); // read serial data + while(serial.readable()) + rxBuf[rxLength++] = serial.getc(); // read serial data } /** @@ -76,9 +84,6 @@ * @retval */ int main(void) { - UIPEthernet.begin(MY_MAC, MY_IP); - myServer.begin(); - serial.baud(BAUD); serial.attach(&onSerial); while(1) { @@ -90,8 +95,8 @@ txLength = client.read(txBuf, txLength); // read data received from the TCP/IP client for(int i = 0; i < txLength; i++) // send through serial serial.putc(txBuf[i]); - wait_ms(50); // tune (increase) this if you are loosing some data - client.write(rxBuf, rxLength); // send back to client + wait_ms(50); // receive serial data from device + client.write(rxBuf, rxLength); // send data to client over ethernet } } }
diff -r d39ee3c772e8 -r e38442f3cb74 mbed-STM32F103C8T6.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-STM32F103C8T6.lib Thu Aug 25 10:37:39 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/hudakz/code/mbed-STM32F103C8T6/#9fbbea76d6f6
diff -r d39ee3c772e8 -r e38442f3cb74 mbed.bld --- a/mbed.bld Sat Apr 11 07:23:02 2015 +0000 +++ b/mbed.bld Thu Aug 25 10:37:39 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c \ No newline at end of file