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.

Read a Pin value when configured as SPI.

Status
Not open for further replies.

Gobbledok

Active Member
Hi does anybody know whether we can read a pin value when that pin is configured as the SPI in?


For example, the SST25VF032 flash supports hardware end-of-write detection. Once you have written to the flash IC, you can make the internal busy status appear on the SDO (PIC SDI) pin. Do I have to turn off the SPI module in order to read this status pin?
 
I don't no what chip your using but You can read that status bits and write the 2 upper bits

SSPCON1 and SSPSTAT are the control and status
registers in SPI mode operation. The SSPCON1
register is readable and writable. The lower six bits of
the SSPSTAT are read-only. The upper two bits of the
SSPSTAT are read/write.

The SSPBUF register cannot be used with
read-modify-write instructions, such as
BCF, BTFSC and COMF
 
Last edited:
Hi Burt thanks for your reply.

What I meant was that the Serial Flash's internal busy status will be output on the Flash's SDO pin. I need to read the PIC's SPI Data In pin to check whether the flash is busy or not. I'm not sure whether I need to disable the SPI module in order to be able to read the pin or if I can just read the port like normal. If I could I would just try it but work gets in the way of a lot of things ;)

I am using SST25VF032B and PIC32MX795F512L.
 
Last edited:
What about connecting the SDO pin from the flash to a 2nd PIC pin programmed as an input. That should let you read the pin without messing with the SPI interface.

Having said that. Why use this mode to detect end of write. You can also poll the chip using SPI commands ?
 
Thanks 3v0, nice simple idea. I have plenty of pins :)

Reasons:
1) I wanted to see if it's any faster.
2) I am having some problems with Auto-Address-Increment Write and want to simplify things for myself to narrow down the problem.
 
I think in almost every case a PIC still allows "reading" a port pin, even when the pin is assigned to a hardware module. Many of the early PIC asm projects relied on this feature.

If you check the PIC datasheet under the "IO ports" chapter it usually shows the hardware diagram for a port pin. In most cases there is nothing to disable the port pin read function, although on some newer PICs they may disable the digital input reading if the pin is set to analog mode (which it would not be).

Does your PIC32 datasheet have a diagram for that port pin?
 
Hi Roman thanks for your reply, I didn't think of checking the pin diagram.

The closest thing I could find was an SPI Block Diagram which doesn't specify what the SDO pin does apart from the SPI functions.

SPI Block Diagram.jpg

All else I could find in the datasheet is:
In general, when a peripheral is functioning, that pin may not be used as a general purpose I/O pin.

However of course you can't use the pin as an output (for example) when the SPI module is enabled. I guess the best I can do is try it later tonight and let you guys know if it works.

EDIT: Found the diagram you were talking about:

Multiplexed Port Structure.jpg

It seems to say that reading the port will work fine while another module is enabled (I think). Cheers mate.
 
Last edited:
Thanks for the second diagram Gobbledok, that's the one that shows the input function although it's a "generalised" pin.

It looks fine, reading the port pin should read the digital level on the pin at the instant the read takes place. That's pretty standard, even if a pin is an output or a hardware module is driving the
pin.

Of course it is always a good idea to test it out!
 
Please let us know what you find.

Hi 3v0,

Just tried it... Reading the SDIx pin works fine when the SPIx module is enabled.
 
That's cool I just read both data sheets and was going to post them pic32 have alot of data sheets to read
but the pin you wanted to read is a digital input it should be readable now we no have to keep that in my book.
 
...pic32 have alot of data sheets to read...

Yeh tell me about it. In my PIC32MX795F512L folder I have 29 Microchip Datasheets! That's only core and peripherals too, not application notes.
 
Given that you have pins to spare the ability to use the same pin is a matter of curiosity.

Please let us know what you find.

Im not sure it's a matter of "curiosity" as the PIC pins were always designed so the PIC can read a pin even when it is set to be an output pin.

When hardware output modules are enabled the normal pin output drivers are used so the pin can still be read.

The closest thing I've found to an exception is one some PICs when the pin is set to be "analog input" it can disable the digital input driver (probably to avoid input latch up excess power consumption etc as mentioned in the datasheet).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top