Using PICs as UARTs


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2005
    Posts
    1,073

    Angry Using PICs as UARTs

    I need to add multiple serial ports to a project. I plan to use four PIC12F1840s with hardware EUSARTs and internal oscillators running independently and communicating with the main processor (ATmega1284P) via I2C. The PICs will be pre-programmed SMD and the boards will be assembled in China. There will also be a PIC12F1822 handling a half-duplex RS485 network and communicating via I2C and a MAX3421E USB Host using SPI to the main processor. I would like the four RS232 PICs to share an INT line and the main processor will poll them for data when the INT is activated but could just let the main processor poll them periodically. In my application, data is sporadic and rather sparse with 19200 being the maximum rate (at this time) but the PCB will be an Arduino compatible shield so it may be put to more demanding uses.

    My questions:

    1. The only functions will be serial I/O and I2C. Will On Interrupt be adequate to service the serial port and/or the I2C bus or will I need to use DT's ASM interrupts? If the latter, can you point me to example code I can adapt?

    2. I would like to find a way for the four serial port PICs to self-identify their I2C address. If I use an INT line, each has only one free pin (Pin 4, input only). If I don't use an INT line there is another free pin and I can use those for a 2-bit address. Can anyone suggest a way to do this with one input-only pin? One way would be to use two different PIC models, then 1-bit is sufficient but I need PICs with similar capabilities - hardware UART & hardware I2C.

    3. What are the flaws in my hare-brained scheme?

  2. #2
    Join Date
    Dec 2005
    Posts
    1,073

    Default Re: Using PICs as UARTs

    I should have checked one thing before posting. The ds30 bootloader now supports both the 12F1822 & 12F1840 so that simplifies things. At assembly, all can be blank except for the bootloader and the program & I2C address can be added later.

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default Re: Using PICs as UARTs

    What do you mean by "self identify"? Do you mean that you want each one to automatically pick up a separate I2C address?
    Can you set up the Atmega as an I2C slave?

    I have all sorts of stuff you could probably use. PM me for more information.
    Charles Linquist

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: Using PICs as UARTs

    Quote Originally Posted by dhouston View Post
    the boards will be assembled in China.
    What are the flaws in my hare-brained scheme?
    You have answered you own question.

    I have no opinion about the fesability of your design, but from what I have seen here from your other posts, I am sure it will be great.

    [soapbox]
    Don't get me wrong, I buy imported stuff all the time, but as a small shop, I know all too well the impact of sending our manufacturing overseas. I was even coerced into trying this myself. It did not pay off in the short run, and will never pay off in the long run. IMHO

    When we send the "gravy" work out, the manufactures here have to rely more on prototype stuff to pay the bills. So then we have to pay more for the proto work.
    [/soapbox]
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Aug 2011
    Posts
    412

    Default Re: Using PICs as UARTs

    If you don't mind setting a unique ID in the UserID area when you initially program the chip (say 1 to 4 for example), then you could use this setting to identify which of the four uarts the chip is supposed to be and have the master use the General Call address feature of the I2C to assign a new address to the device at powerup. It could be as simple as sending a packet to the General Call address consisting of the ID number and the new address.

    No additional lines required.

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default Re: Using PICs as UARTs

    dhouston, Doensn't the pic have an A/D? With a couple of fixed 1% resistors you can have quite a few addresses...
    Dave Purola,
    N8NTA
    EN82fn

  7. #7
    Join Date
    Dec 2005
    Posts
    1,073

    Default Re: Using PICs as UARTs

    Quote Originally Posted by cncmachineguy View Post
    You have answered you own question.
    First, the decision to have the boards made in China is not mine but the distributor's (who is helping fund the development).

    Second, were it my decision, they would still be made in China. It's the difference between having something that can be sold at a competitive price and having something that cost 5x the market retail price with no hope of selling any. The Arduino market has thousands of boards available selling for $10-50 depending on whether bare, kits, assembled and on what's onboard. The last time I looked at US assembly was about 10 years ago - the president of the company was a friend - the quote was about 10x what I could get them for from China.

    Third, I spend about 20 years in the machine tool industry culminating in my running the US operations for a (small) multinational builder of machine tools so I empathize with your position but, it's about 30 years too late. The Reagan administration decimated the US machine tool industry and it's not likely to ever recover. (ASIDE: One of my customers made programmable machines that assembled through-hole components onto PCBs - I never dreamed I might want one thirty years later.)

  8. #8
    Join Date
    Dec 2005
    Posts
    1,073

    Default Re: Using PICs as UARTs

    Quote Originally Posted by tumbleweed View Post
    If you don't mind setting a unique ID in the UserID area when you initially program the chip (say 1 to 4 for example), then you could use this setting to identify which of the four uarts the chip is supposed to be and have the master use the General Call address feature of the I2C to assign a new address to the device at powerup. It could be as simple as sending a packet to the General Call address consisting of the ID number and the new address.
    I guess I did not explain my concerns clearly.

    Microchip will preprogram chips when you order them. All four chips will be have identical firmware except for the I2C address which must relate to a physical port (S2-S5) which is, in turn, related to the physical location of each chip on the PCB.

    The logistics of keeping 4 separate chips separate and then assembling them to the correct PCB location is what scares me. On another board, I have two sets of two identical chips (2x12F1822, 2x16F1823), that ID themselves upon startup by the state of one input which is grounded for one socket and tied high for the other - and these are DIP chips with sockets so it's not as critical that they be assembled correctly. I was trying to find a way to extend that to handle four identical chips.

    However, the issue is now moot. The ds30 bootloader has been updated to support all three PICs I am using (12F1822, 16F1823, 12F1840) and it allows writing EEPROM so they can have the bootloader installed by Microchip and then be programmed over a serial link after assembly or even by the end user.

  9. #9
    Join Date
    Dec 2005
    Posts
    1,073

    Default Re: Using PICs as UARTs

    Quote Originally Posted by Dave View Post
    dhouston, Doensn't the pic have an A/D? With a couple of fixed 1% resistors you can have quite a few addresses...
    Dave - I had thought of that but I am using the hardware EUSART and the hardware I2C so the only free pin is the MCLR pin which is input only - no ADC.

    But, see my answers above - the availability of the ds30 Bootloader for the chips I'm planning to use solves my problem.

  10. #10
    Join Date
    Dec 2005
    Posts
    1,073

    Default Re: Using PICs as UARTs

    Quote Originally Posted by Charles Linquis View Post
    What do you mean by "self identify"? Do you mean that you want each one to automatically pick up a separate I2C address?
    Can you set up the Atmega as an I2C slave?
    On another board I use 2x12F1822 and 2x16F1823. Pin 4 (RA3) is free on each and whether it is tied high or low allows the chips to know which port they are associated with and assign their own I2C address. I was looking for a way to extend that to 4 identical chips associated with distinct input connectors.

    However, I have since checked the ds30 Bootloader site and see it has been updated for the chips I plan to use. The bootloader can write EEPROM so they can all be preprogrammed with just the bootloader and have the application firmware and I2C address downloaded after assembly or even by the end user. It solves the logistics problem of maintaining separate inventories of chips that are identical except for their I2C address.

    Quote Originally Posted by Charles Linquis View Post
    I have all sorts of stuff you could probably use. PM me for more information.
    Thanks, I'll PM you with additional details later today.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts