RS232

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
ZONK
Posts: 11
Joined: Thu May 25, 2006 3:34 pm
Contact:

RS232

Post by ZONK »

I have pic micro development board v2 and trying to use flowcode to build project.
I can use flowcode for simple LED flashing projects and delay switching etc but I am having difficuly in programming chips ie pic16f628 to communicate to an rs232 peripheral device (not a pc).
I need to transmit 4 bytes of binary code of which each are 8 bits long to a video multiplexer.
The reason for this is there are a lot of buttons on this unit that the end user will freak out on, hence the reason for building a 2 button switch unit to comminicate to the device. One button to send one set of 4 bytes to carry out a specific function and the other another set of 4 bytes for another function.
Please could some one show me how to accomplish this bearing in mind source programming skills are nearly non existant.
I have done a lot of reading regarding usart, bit bashing rs232 protocols but still am frustrated but will persevere.

User avatar
Steve
Matrix Staff
Posts: 3426
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

Here are a few suggestions that might put you in the right direction:

The RS232 given out by the FlowCode component is 8 data bits with one start bit and one stop bit. The CTS and RTS lines are also controlled if you select "hardware flow control", otherwise you would need to manipulate these signals yourself.

Baud rate is also important, so make sure you have set the board rate to that of the device. Bear in mind that the RS232 component assumes the clock speed is 19.6608MHz - if you are using a different clock speed then you will need to create your own RS232 comms (take the 'C' code created by FlowCode, alter it suitably and then add it to 'C' icons within your flowchart).

Another thing to be aware of is the voltage levels of RS232 - they are not generally TTL (0 - 5V) levels, so you would need to use a voltage shifter chip (or use our RS232 E-Block) to convert the signals between the PICmicro and your device.

Also your RS232 device might expect certain other RS232 signals to be used - e.g. DSR, DTR. You may need to set (or read) these additional pins appropriately.

I hope this helps. Other forum users may have more experience with RS232 and may be able to provide more help.

ZONK
Posts: 11
Joined: Thu May 25, 2006 3:34 pm
Contact:

RS232

Post by ZONK »

Thanks for your reply Steve,
Since the last time I have been doing a lot of researching and acted on your advise.
I built a circuit board containing Pic16f625and a max232 rs232 interface chip and several capcitors and 5v regulator circuit. ( This is not too difficult for me as I am a service engineer). I am outputting on RB2 of Pic chip and inputting on pin10 of max232 then output on pin 7 to pin2 of rs232 port. I have tried what feels like hundreds of ways with flow code to try and create my 4 bytes of binary code 10000100 / 10000001 / 100000010 /10000001 at 9600 baud rate.
I have made sure my oscillator is set at 20Mhz etc but still to no avail.
Could some one show me how to achieve this in flowcode and perhaps show me example.
I am not looking for an easy way out but my head will explode shortly and I may revert to plan B to work my video multiplexor remotely ie Hard wire the necessary buttons. My problem maybe with understanding Interupt settings amongst others?
Thanks

jimhumphries
Posts: 112
Joined: Wed Oct 12, 2005 6:29 pm
Location: USA
Been thanked: 1 time
Contact:

Post by jimhumphries »

Sonk:

If you have done this and it doesn't work I appollogize for wasting your time.

Open "new". Pull down "PIC" and select your Target PIC, Clock Speed (20000000), Configure for XTAL and Watchdog timer Off.

Attach an RS232 object and set Properties for your baud rate and Bytes - click "Apply" and close properties.

Drag an equate object into the program line and double click the object. Create the variable BYTE1 and set BYTE1 = the decimal value of your first byte.

Drag a macro object into the program line and double click the object. Select Call I/O Device Macro, RS2320 and SendRS232Char. Click Variables and select variable BYTE1. Choose Use Variable and Click OK.

Drag a Delay object into the program and double click the object. Set the delay value to 5 seconds and click OK.

Drag an equate object into the program line and double click the object. Create the variable BYTE2 and set BYTE2 = the decimal value of your second byte.

Drag a macro object into the program line and double click the object. Select Call I/O Device Macro, RS2320 and SendRS232Char. Click Variables and select variable BYTE2. Choose Use Variable and Click OK.

Copy the delay object from above and paste it here into the program line.

Repeat for BYTE3.

Drag a loop object into the program and cut and paste all this iinside the loop. Double click the loop object and set Loop while to 1 = 1. Test at the beginning or end.

Make sure that your MAX232 is connected correctly to the designated RX and TX pins shown for your device in the Microchip data sheet.

Compile and run your program and you should transmit a byte every 5 seconds (BYTE1, delay, BYTE2, delay, etc.).

Observe this with a terminal emulator running on your PC and you should at least see something received every 5 seconds. Bytes where the most significant bit is 0 should produce ASCII characters on the terminal emulator. The emulator may go nuts for bytes where the most significant bit is 1.

XXX Steve: I think this should work - do you concur? XXX

Let us know if that works. If it does you can probably take it from there.

Regards,

Jim

ZONK
Posts: 11
Joined: Thu May 25, 2006 3:34 pm
Contact:

RS232

Post by ZONK »

Thanks for your reply,
I can`t attatch an rs232 object to the program line , I only have LEDs, LED7seg10, a thermometer symbol, LCD display, switches and LED7seg40 as object atatchments.
Am I missing something? I am running flowcode V1.0 on a version 2 pic micro development board and currently experimenting with 16f628
I have even tried importing an assembly code into the C code option box inserting it onto program line and even managing to be able to compile it without errors from other forums but to no avail.
Looking forward to your reply.

jimhumphries
Posts: 112
Joined: Wed Oct 12, 2005 6:29 pm
Location: USA
Been thanked: 1 time
Contact:

Post by jimhumphries »

Zonk:

Sorry - I misunderstood. I thought you had Flowcode V2 and had built your own board with your PIC and an RS232 IC. If you can't get this working with V1 (and if you have the spare change) you may want to upgrade to V2 Pro - it has the RS232 support.

Another route - if you have access to "Serial Communications" by Roger Stevens (in the Square 1 "Using PIC Microcontrollers" series), check out chapter 5 on bit-banging asynchrous communications. I think any of those examples can be Flowcoded without having to use the PIC's Universal Asynchronous Transmitter/Receiver hardware. A long way around perhaps but it would get you there.

Regards,

Jim

Post Reply