Hello,
in my project Web Platform could be used to collect data from 4 RS-232 lines, max 400 messages per day. What would be the easiest way to add 4 serial ports to current design?
There are PIC32 with 6 UARTs. Would it be a big effort to redesign the current board to PIC32? How is about the reusability of existing code for PIC33 if I would start the project with PIC32?
Thanks and regards,
srdjan
Do all devices talk to you at the same time, do they round-robin? Do you initiate the comms or the other devices? I'm wondering if it's possible to use the one free hardware UART module and use the peripheral mapping feature to switch the UART between different pins in the GPIO header. Might be possible to use interrupt on change to re-config the UART in time to get the second byte of each serial communication if that is enough. Obviously much easier if you are the initiator as you can rewire Rx before Tx.
If you need truly asynchronous reception on 6 lines, and can get away with RX-only with a low baud rate it should be possible to use interrupt on change features to bit-bash the RX ports on GPIO lines. Use a free running reference timer and sample-on change then some analysis to infer the bits sent. More tricky if they are all using there own oscillator sources due to drift (ie. might not be able to share a common timer unless you have a very quick timer to oversample).
Logging messages out to external flash and the web gui are more tricky :-)
I think the PIC 32 version would be similar, but it would take a lot of software and hardware rework. There are probably reference designs at Microchip you could use as a starting point that would need fewer changes.
Thanks for both answers.
The devices work in round-robin mode. PIC is always the initiator and sends the request (query the device), device responds with 16 to 32 bytes long message. In the main loop PIC should sequentially query all devices. In that regard I did not understand what "rewire Rx before Tx" means? Could you please let me know more about that design?
GUI is not needed but why adding external SRAM or FLASH should be tricky with PIC32? I found also the description how to use parallel master port (PMP) to add external memory: Page 71 of PIC32 Family Ref.Manual http://http://ww1.microchip.com/downloads/en/DeviceDoc/61128D.pdf
Regarding re-work, sounds like interesting project, to me at least.
Here's some example code (based on Ian's) used by the webplatform to assign UART0 to be 'wired' to a particular set of pins. In this case it's to pins RP14/RP15 which the PCB has routed to the FTDI chip for USB serial port debugging.
https://github.com/shuckc/contiki-mirro ... m/serial.c (https://github.com/shuckc/contiki-mirror/blob/master/platform/dp-webplatform/serial.c)
void dbg_setup_uart(void)
{
//UART1 SETUP
//UART can be placed on any RPx pin
//configure for RP14/RP15 to use the FTDI usb->serial converter
//assign pin 14 to the UART1 RX input register
//RX PR14 (input)
RPINR18bits.U1RXR = 14;
//assign UART1 TX function to the pin 15 output register
//TX RP15 (output)
RPOR7bits.RP15R = 3; // U1TX_O
//peripheral setup
U1BRG = 85; //86@80mhz, 85@79.xxx=115200
U1MODE = 0; //clear mode register
U1MODEbits.BRGH = 1; //use high percison baud generator
U1STA = 0; //clear status register
U1MODEbits.UARTEN = 1; //enable the UART RX
IFS0bits.U1RXIF = 0; //clear the receive flag
U1STAbits.UTXEN = 1; //enable UART TX
}
I have another example I can dig out where I route UART1 to pins on the extension port "GPIO" header as an application serial port. You need to look up in the DP schematic which pins from IO1 header you want, and the corresponding RPx number.
http://dangerousprototypes.com/docs/Web ... I/O_Header (http://dangerousprototypes.com/docs/Web_Platform:_I/O_Header)
IO1 pinout
pin Lbl PIC PORT# RP# Output Max input
1 IO1 35 A9 - 3.3v 5.5v
2 IO2 36 C3 19 3.3v 5.5v
3 IO3 37 C4 20 3.3v 5.5v
4 IO4 38 C5 21 3.3v 5.5v
5 IO5 42 B6 6 3.3v 5.5v
6 IO6 41 B5 5 3.3v 5.5v
7 IO7 44 B8 8 3.3v 5.5v
8 IO8 43 B7 7 3.3v 5.5v
9 GND - - - GND -
10 3.3V - - - 3.3v -
You should be able to wire four devices to have there own 2 pins each (8 pins). eg. RP19,20 for device #1, RP 21,6 for device 2 etc. There's only 7 RP ports on Header IO1, so you'll need to steal another from somewhere else. My advice here is to re-purpose one of the lines going to the SPI EEprom chip since they are also taken to a pin header (I've done this to get I2C on this board). Your software needs to modify the values in registers RPINR18 and RPOR7 to select which module of the four you want to speak to each time.
Bear in mind the pins are only 3.3V outputs, that could be lower than TTL serial UART converters take on the input - check the datasheet as you might need a transister driver to pull it up. If your devices are full RS232 serial ports, they will be outputting/expecting -12V/8V or whatever it was that seemed a good idea in the 70's. Grab a few breadboard compatible MAX234's dual drivers from Maxim on eval, and recommend a resisters divider for the output 5V -> 3.3V shifter to avoid sinking too much through the input buffer protection diode and you should be set.
Chris