SPI problem with PIC18F26K22

General discussion on mikroBasic.
Post Reply
Author
Message
k.ifantidis
Posts: 15
Joined: 23 Nov 2012 23:17

SPI problem with PIC18F26K22

#1 Post by k.ifantidis » 11 May 2015 15:37

Hello there i would like to ask something. If i enable the HW spi peripheral of the pic, can i high/low pic's SPI pins after the SPI initialization ?!
An example of what i mean.
1. Init SPI2, PB1=CLK, PB2=SPIinput, PB3=SPIoutput.
2. I need to high/low some times the Clock and the SPIoutput (PortB.1 and PortB.3 pins)
3. After this, i want to use the spi module 8bit mode to sent data (i never receive data because i don't need to. So i dont use SPIinput pin)

I have tried to do so but it seems if i enable the SPI peripheral PORTB.1 and PORTB.3 can't be setted High or Low.
The thing is that i don't know how does SPI library affects the PINs after enabling.
If there is anyone with more experience than me on the matter i would appreciate the help.

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: SPI problem with PIC18F26K22

#2 Post by marina.petrovic » 12 May 2015 10:48

Hi,

Compiler SPI Library and SPI routines are written according to SPI standard, which means that SPI initialization routines set all appropriate registers and pins according to SPI standard and MCU datasheet.

SPIx_Init() routine configures and enables SPI module with the following settings:
- master mode
- clock Fosc/4
- clock idle state low
- data transmitted on low to high edge
- input data sampled at the middle of interval

also, according to datasheet:
- SDIx must have corresponding TRIS bit set
- SDOx must have corresponding TRIS bit cleared
- SCKx (Master mode) must have corresponding TRIS bit cleared

additionally in code:
- SSx must have corresponding TRIS bit set

If you want to use SPI communication with some specific task, you can try to write your own SPI routines (for initialization and communication).

For any additional information, please, take a look at PIC18F26K22 datasheet - page 214.
http://ww1.microchip.com/downloads/en/D ... 41412F.pdf

Best regards,
Marina

k.ifantidis
Posts: 15
Joined: 23 Nov 2012 23:17

Re: SPI problem with PIC18F26K22

#3 Post by k.ifantidis » 13 May 2015 19:39

Hello Marina, thank you for shedding light in this case. I did read a lot posts and the library but i couldn't find this info. I created mine SPI routines and the device worked perfectly!
Regards, Kostas.

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: SPI problem with PIC18F26K22

#4 Post by marina.petrovic » 15 May 2015 08:38

Hi,

You're welcome.
I am glad that now everything works properly.

Best regards,
Marina

Post Reply

Return to “mikroBasic General”