views:

81

answers:

3

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?

+1  A: 

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.

John Burton
+4  A: 

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.

peter_mcc
any links for SPI implementation? Not sure where to start.
onaclov2000
http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Busbit banging the spi bus is not a big deal. or rs232 for that matter. If you just want a debug channel with the rs232, you can bit bang just the transmit and save the uart pins for whatever other interface shares those pins.
dwelch
bit bang means software configures the gpio pin as gpio, general purpose. You use a tuned counting loop or timers in the chip for timing. So to transmit rs323/serial instead of writing the byte to some register, fire and forget, you send the start bit by changing the gpio output level, count for how many clock cycles it takes to make the start bit long enough, then take the first (lsbit) of the byte you want to send, set the output level for that, count clocks until that bit cell is done, repeat, send the stop bit, leave the output in the idle state. spi is the same just more i/o lines
dwelch
That is really great, I mean I kinda understood it like that, but haven't ever really sat down and done it, I would like to play with that for sure.
onaclov2000
A: 

I strongly recommend that you change the MCU with PIC16F1933.

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

The PIC16F913 MCU will become obsolete in next few years!

GJ
I think I bought it because it was stated on the PickKit 2 board info that the 913 was supported, I'm not sure how that is the case, but at least using ICSP I can program it, other then that I don't know how else to program it (Do other people program it on the actual board?)
onaclov2000
Yes, ICSP is normal way to program it. Of course you can also program it in ProMate programer, but this is normaly for factories. 16F913 is compatible with PICKIT 3.
GJ