2
votes

Here is my issue, it appears that all the communication lines for the PIC 16F913 reside on the same set of pins, this is convenient in that I don't have to sacrifice GPIO pins just to do comms, however the problem I'm having now is if I'm using the SPI on the chip, how can I send information to the RS232?

The reason this issue came up, is that I just bought a CAN bus chip that communicates over SPI, and I would really like to see the data on RS232, so I can see messages. (I really don't know much about CAN yet, so who knows if this even makes sense yet).

Here are the options I see, and maybe someone else has better ideas that I'm just simply missing.

  1. Somehow setup a time scheme that will switch between SPI and RS232 every time I get data,

-- This doesn't seem hard and should work, but supposing I don't want to miss a message, what if a message is written while I'm writing to RS232, is it possible I'll miss it?

2.. I can always use SPI, but then build my own comm bus over 8 of the GPIO lines, to another PIC 16F913, using only the GPIO lines and then since the RS232 lines are free on the second PIC I can simply read the data and spit it out.

-- This one is doable but now we're wasting 2 chips, AND all the GPIO lines,

There has to be a better way. Or is there?

Any help is greatly appreciated.

Update: I would like to clarify, obviously one solution is using a completely different chip (which may in fact be what I end up doing, if I can get the 18F programmed), however, I'm interested in worst case scenario, in which I am limited in resources and only have some 913's, is the way described above the only way to do it with this chip, or is there a better way?

3
Why do you have to use the 16F913? Most parts in the 18F series would easily have enough resources to use the MSSP and EUSART modules at the same time; and some of those (the 18F25J11 for instance) allow you to reconfigure which pins that the peripherals use, so you wouldn't need an 84-pin device just to use separate modules like that. - Mark Rushakoff
Well unfortunately I have the pick kit 2, which will program via ICSP, but for some reason I can't get the 18F4550 that I have to program using it. so I'm kinda stuck on the 16 series. I'm wondering if it's a matter of voltage for the 18 series, I'll need to look into that in the near future (School's almost out for the summer...woot) - onaclov2000
Did you pull the PGM pin low to disable low voltage programming mode? Letting the pin float is the usual problem I have with those. - jcoder
There's a couple parts in the 18F series (such as the 18F14K50) that you need an adapter to regulate the programming voltage when you're using an ICD2, at least. But this tutorial suggests that you do not need any such adapter for the hardware you've described. Double check your wiring and make sure your protection diode is set up right (or try taking it out, that helps me sometimes). - Mark Rushakoff
Thank you both, I didn't do any real investigation as to why it wasn't working, but it looks like the tutorial Mark suggests does use an external P/S, I was just using straight USB powered, as for the PGM pin low, I'll have to look, I'm not certain, in reality I just hooked up the what 4 pins for programming, and just hit "program" the other problem I was having is that MPlab doesn't recognize that I have a ICSP setup, so I have to use the PIK Classic env (I might be wrong on the name). Wasn't sure if that also just didn't recognize it. - onaclov2000

3 Answers

4
votes

You could do a software implementation of the SPI bus - it's easier to do than the UART because the timing isn't critical and you are in control of it.

Most CAN chips have a few receive buffers so if you're busy doing something with the UART then the messages will be buffered inside the CAN chip. But... you will need to make sure that you can get the messages out of the CAN chip fast/often enough so you don't lose some.

You would probably have to either use an interrupt for the UART Tx process - so that you can be receiving CAN messages while you're sending data on the UART.

If you're only interested in certain messages most CAN chips have filters - this makes it easy to only receive the messages you're interested in, usually dropping the number of packets/second dramatically.

1
votes

You can use a software implementation of a RS232 port. For example the c compiler from http://mikroe.com comes with such a library. But it shouldn't be too hard to shift bits to an output pin, rs232 is a fairly simple protocol.

1
votes

I strongly recommend that you change the MCU with PIC16F1933.

  1. It is newer
  2. It is cheaper
  3. With EUART and MSSP moduls.
  4. The MCU arhitecture is impruved.

The PIC16F913 MCU will become obsolete in next few years!