1
\$\begingroup\$

Is it possible for anyone to make a PIC(I'm thinking of using 16F628/16F628A) communicate with another device, in this case a digital scale or industrial digital multimeter using USART/serial port communication?

I know that connecting digiscales to PC and reading data thru serial ports is possible (I've done this before so I know I could). I was just wondering if anyone has ever tried to use PICs or any microcontrollers in place of PC. The change is needed since where I am going to implement this thing, the PC option can't be used(it's not there), and using PIC is much much cheaper.

I got codes for a 16f84 communicating to a PC with me(got it off electronics-diy.com, somehow blocked now), gonna try converting it to 16f628A compatible first. Anyone who has ideas do share.

\$\endgroup\$
  • \$\begingroup\$ It looks obvious to me, if you already done this on a serial port, to use the same for your PIC. Use a MAX232 or similar to convert the EIA-232 levels to the PIC's \$\endgroup\$ – stevenvh Jun 28 '11 at 10:38
  • \$\begingroup\$ I was just wondering if serial port on PC side can translate into PIC side as well. Matt Jenkins already elaborated on that so yeah I suppose it's doable. \$\endgroup\$ – Sodrohu Jun 28 '11 at 10:49
  • 1
    \$\begingroup\$ I see Matt gave you a good answer, but you're not likely to hear thoughts from others since you accepted his before anyone else had a chance to say something possibly different. \$\endgroup\$ – Olin Lathrop Jun 28 '11 at 11:50
  • \$\begingroup\$ I guess I should've waited more, but after I accepted someone's answer other people can still post here right? \$\endgroup\$ – Sodrohu Jun 29 '11 at 1:59
2
\$\begingroup\$

The PIC has an industry standard UART, and anything the PC can do the PIC can do as regards communicating.

The only difference between the two is the PC will most likely have an RS-232 line driver in the circuit to provide the proper +/-12V or so. The PIC doesn't have this, but adding something like a MAX232 chip will convert the output to standard RS-232 levels.

All you need to know is the correct protocols to use to talk to the remote device, and to implement them in the PIC's firmware. Note that the PIC doesn't have any hardware handshaking as standard, and a very tiny (2 character) receive buffer, so I tend to write my own send/receive routines which implement hardware handshaking using a couple of other I/O lines which also go through the MAX232 chip (CTS/RTS).

Getting the right baud rate setting on the PIC can be a little tricky, depending on which specific language you are programming in - some calculations are often required to get the divisor from the system clock speed. The data sheet is essential for this - read it thoroughly.

\$\endgroup\$
  • \$\begingroup\$ Yeah, I figured out that I need to convert the RS232 from 12V to TTL 5V to get it working - it's the software I'm more worried about. I'm using HiTech C in C programming to program the PIC. I'm looking for examples over the net and so far just found some that looks workable. \$\endgroup\$ – Sodrohu Jun 28 '11 at 10:47
  • \$\begingroup\$ It's easy enough - once you have the USART configured it's a matter of checking send/receive flags, and writing to / reading from buffer registers. \$\endgroup\$ – Majenko Jun 28 '11 at 10:49
  • 1
    \$\begingroup\$ Thanks for the answer. I'll start by reading the datasheet first. \$\endgroup\$ – Sodrohu Jun 28 '11 at 10:53
  • \$\begingroup\$ @Sodrohu - Reading the datasheet is always a good thing to do! \$\endgroup\$ – Kevin Vermeer Jun 28 '11 at 13:22
  • \$\begingroup\$ I read the datasheet, and it says USART has either asynchronous or synchronous mode - which one should I choose? \$\endgroup\$ – Sodrohu Jun 29 '11 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.