Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Communicating with PC via serial PORT using SPI?

Status
Not open for further replies.

PICMICRO

New Member
Hi, I have already implemented UART communication with PC via the com port (serial port). Is it possible to communicate using the SPI module in the uC as well?
 
The FT2232H chip is relatively easy to use if you want to communicate with PC via SPI bus.
I believe you can buy a USB to SPI interface adapter module somewhere, but I didn't find any at the moment.
 
Last edited:
Yes! they are entirely different modules inside the pic ( providing both are available ) even if there is no MSSP on-board most libraries contain a software implementation anyway.

Ian

Hi there.
Seems like the SPI needs a spearate Clock line. The standard RS-232 doesn't have clock line. How do I use it? Oh! wait, how does USRT works? Where is the clock line there? Can use USRT for SPI ?
 
Hi there.
Seems like the SPI needs a spearate Clock line. The standard RS-232 doesn't have clock line. How do I use it? Oh! wait, how does USRT works? Where is the clock line there? Can use USRT for SPI ?
hi,
Which programming language are you using on the PC.??
 
Usart communication (std RS232) is what they call asynchronous, The bits arrive sequentially determined by the baud rate.. SPI however is synchronous, you need a clock to time the bits in and out. SPI communication is faster than the usart as speeds can be in the order 500kbs.

I believe you can use the usart for synchronous communication, but you will have to read up on that.

Ian
 
Can use USRT for SPI ?

No. Gets very messy and slow.. if even theoretically possible.

What exactly is it you want to do? A microcontroller communicating with PC using SPI on the microcontroller and COM-port on the PC?
 
Last edited:
Here is what I am trying to do.
Communicate (Exchange Data) with the PC.:D
The problem is I want to use PIC16f72 which don't have USART but only SPI.
I had been using matlab and its built-in UART libraries for communications.

I don't need to exchange data too often, only occasionally. But I am afraid of using Software UART because, I think I should be polling the Rx pin every now and then to check if data is coming. I can't waste precious processing time polling. If I could generate Interrupt only when data arrived, that would be fine too!
 
What exactly is it you want to do? A microcontroller communicating with PC using SPI on the microcontroller and COM-port on the PC?
Exactly.
Added this line to workaround 10 characters limit.
 
Last edited:
I think I should be polling the Rx pin every now and then to check if data is coming. I can't waste precious processing time polling. If I could generate Interrupt only when data arrived, that would be fine too!

If you use the RB0/INT pin (of the PIC16f72) for receiving (RX), you can use the external interrupt to detect incoming data. That way you don't need to poll the RX. You can also configure timers with interrupts to receive the incoming bits after you have detected the "data start bit".

EDIT:
"A microcontroller communicating with PC using SPI on the microcontroller and COM-port on the PC" requires an interface adapter chip between the microcontroller and the PC. No way you can do SPI<->RS232 communication with simple connections and software.
 
Last edited:
Here is what I am trying to do.
Communicate (Exchange Data) with the PC.:D
The problem is I want to use PIC16f72 which don't have USART but only SPI.
I had been using matlab and its built-in UART libraries for communications.

I don't need to exchange data too often, only occasionally. But I am afraid of using Software UART because, I think I should be polling the Rx pin every now and then to check if data is coming. I can't waste precious processing time polling. If I could generate Interrupt only when data arrived, that would be fine too!

Don't get confused guys, that was actually myself. This is a shared computer , and I didn't realized, it was actually my brother (thecritic) logged in as opposed to myself. I should suggest him to properly log-out when leaving computer or be suggested back to properly check who is logged in before posting:D .
 
Can we go back to Eric's statement... What language are you programming in...If it's assembler, put the RX routine in a ISR using RB0 as MisterT advised, then you don't need to poll the serial transmission. If a higher level language.... well we can take it from there.

Ian
 
Thanks guys. I am going to use microC (its has software uart routine) on the PIC and Had been using Matlab in the computer side. Oh! yeah, using RB0 for RX (in the software uart) sounds like wonderful idea. But wouln't I be missing a bit or two, since I would be interupted by the data I want to recieve?
 
But wouln't I be missing a bit or two, since I would be interupted by the data I want to recieve?

No, the interrupt is very fast compared to the data rate of uart. The interrupt detects the start of the first bit immediately when the data line changes state.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top