PDA

View Full Version : PIC and MAX232 in/out



The Master
- 29th March 2008, 17:17
Hi. I made some circuits a while ago that take commands from a PC through serial. The circuits could also send out serial to each other. Since then ive been told i really shouldnt be using the method i was using and i have to put a MAX232 chip (or similar) between the PICs and the PC.

I have 3 wires. DataIn, DataOut and Common. When the PC is sending the commands this isnt a problem. PC > MAX232 > PIC. I know how to do that much. The problem comes when the PC isnt around and one of the PICs wants to send commands. How do i go about doing that?

Before i simply used the seriout command on the same pin that usually used serin. This time i will be using hardware UART so i can do PWM and a MAX232 chip. Both of those things stop me from sending data out of the DataIn wire.

I had a thought. Can i use a seperate pin on the PICs so when its set as the master it uses serout on some other random pin which makes use of the second output of MAX232. Connect the output of the MAX232 into the input (the DataIn wire). The master chip will ignore itself and the others will listen.

Is this possible? Is it the best way? Will it work without something exploding? lol

mackrackit
- 29th March 2008, 17:23
If you have the in line resistor between the PIC and PC the MAX chip is not needed. The MAX chips are for inverting signal levels and adding some boost to the transmission..

If you were using USART then yes you need it, but then it would not work with out one.

So, the software SERIN/SERIN2 is OK straight to the PC if the distance is short enough.

The Master
- 29th March 2008, 17:34
I plan to use these circuits in my disco lights. Im using 3 pin DMX cables but the last light could be a total of 30-40 meters of wire away from the PC.

Im using the serial RX/TX pins on the pic chip. Last time i tried that i was told its impossible without a MAX232 chip. When in slave mode the chips wont be using serin. It will use the other code which i cant remember off the top of my head but it reads bytes straight from the buffer.

As far as i know i would need a 3rd pin for one of them to act as a master. When acting as a master a normal serout should work fine but its how to connect that pin into the DataIn wire so all theo ther lights pick it up

mister_e
- 29th March 2008, 17:47
Usually DMX will use something like a 75176. Open the datasheet, and see how you could trick it.

But MAX232 is really not what you need to use to meet the real DMX protocol/requirement.

The Master
- 29th March 2008, 17:49
Sorry if i wasnt clear. Im just using DMX wires. The actual circuits will use RS232

mister_e
- 29th March 2008, 17:54
Depending your baudrate and if you need interrupt, SERIN/DEBUG/SERIN2 may have their advantages.

HSERIN's timeout could be handy in this case. You send data, next line is a HSERIN if the timeout happen, you do something else.

Maybe i need another coffee :o

The Master
- 29th March 2008, 17:59
Yes i do need interrupts. Im going to add PWM to this version. Im making sure i have the correct pin connected to the diodes for zero crossing this time too.

The baud rate will be standard 9600 although im going to try and speed it up a bit. Ill think about that later though

mackrackit
- 29th March 2008, 18:22
Maybe need RS485 if you have multiple drops. And yes, you will need the converter if you use the hardware pins. But like MisterE said , lots of options.

The Master
- 29th March 2008, 18:31
I have been reading about RS485. It looks like i need a special converter between my PC and the chips (RS232 > RS485 converter). Would it just be easier to continue with RS232 but not allow any of the PICs to act as a master? If im going to need extra hardware to RS485 anyway then i might aswell have a small box that acts as the master. Thinking about it this might be the best way

mackrackit
- 29th March 2008, 20:18
With RS485 you would need a driver chip at both ends.

The other good thing about 485 over 232 is the 485 can handle longer distances with more reliability. If you do go this way and do not need multiple drops, RS422 is good.

As far as the best way to go for you system is hard to say. I do not fully understand your system and what you want it to do.

Just giving suggestions :)

The Master
- 29th March 2008, 20:41
Ok, Ill give a description of it.

As said before these will go into disco lights. There will be at least 14 lights that all have to run together. The addressing system allows for about 200 lights but realisticly i will never have more than 30. They are connected using 3 pin DMX cables. Inside each light the in/out XLR sockets are wired together (asif the light wasnt even there). Most of the lights will be connected with 1 meter cables but PC>first light and stageleft>stageright could be upto 20 meters

The DataOut pin is only so the lights can send info back to the PC. Things like its ID number so the PC can check all the lights are responding etc.

DataIn is where the data comes into the lights from the PC to tell them what to do.

There is a button on the back of each light. When you press it it checks if the PC is sending an ID. If it is then it changes its own ID to the one the PC sent. If the PC doesnt send an ID then it turns itself into a master where it sends data out of DataIn to all the other lights

The lights need to support PWM for fading.

They do need to work with some existing controllers too. The existing ones are RS232 but they dont need to send data to these so the RS232 output from the PC could go directly to the existing ones then into a converter for RS485/422 and onto the new ones.

Since there will be at least 14 lights i think that means i need 485 and not 422. Will i be able to buy an RS232<>RS485 converter and simply swap the MAX232 chips for a MAX485 (if they existst)? Ive not actually made the circuits yet so i can change pins around if i need to