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.

Both parallel and spi in PIC microcontroller PLEASE HELP

Status
Not open for further replies.

jitun2

Member
I want to perform both Parallel and SPI interfacing in PIC18F2550 microcontroller.I am interfacing a high speed 8bit ADC(either MAX114 or AD7825) to the PortB of the microcontroller and display the value in a Nokia 6100 color(4K) LCD interfaced by using the SPI interface.I will also send the same value to the PC over USB.The USB part is not a problem.

The problem is the pin number 22 which is the PortB.1(RB1/AN10/INT1/SCK/SCL) is also the Serial clock needed for the SPI. Now my question is how can I use both of them simultaneously.Is there any work around for this.

I'm using the CCS C Compiler for my PIC programming.
 
jitun2 said:
I want to perform both Parallel and SPI interfacing in PIC18F2550 microcontroller.I am interfacing a high speed 8bit ADC(either MAX114 or AD7825) to the PortB of the microcontroller and display the value in a Nokia 6100 color(4K) LCD interfaced by using the SPI interface.I will also send the same value to the PC over USB.The USB part is not a problem.

The problem is the pin number 22 which is the PortB.1(RB1/AN10/INT1/SCK/SCL) is also the Serial clock needed for the SPI. Now my question is how can I use both of them simultaneously.Is there any work around for this.

I'm using the CCS C Compiler for my PIC programming.
Can you share the 8 bits of the parallel interface between PORTA and PORTB? My idea is to connect the four least significant bits to RA0/3 and the four most significant bits to RB4/7. RB1 will be available for SPI communication; little elaboration is required to merge the two 'nibbles' into one byte.


EDITED: typo corrected - eng1
 
Last edited:
blueroomelectronics said:
Just put the bit on a free I/O pin. Merge the bit with the other 7 bits in software. Or use a SPI ADC
I was also thinking of a solution like this.i.e. to put the bit on a free pin on port A. or to use 4bit from portA and rest 4 bit from PortB.Can you show me an code snippet in C for doing this.
 
eng1 said:
Can you share the 8 bits of the parallel interface between PORTA and PORTB? My idea is to connect the four least significant bits to RA0/3 and the four most significant bits to RB4/7. RB1 will be available for SPI communication; little elaboration is required to merge the two 'nibbles' into one byte.


EDITED: typo corrected - eng1
I think this code will work for you idea

data1=portb & 0b00001111;
data2=porta & 0b11110000;
data=data1 | data2;

Please correct me if I am wrong.
 
Code:
data1=portb & 0b11110000;
data2=porta & 0b00001111;
data=data1 | data2;
in one line:
Code:
data = (PORTB & 0xF0) | (PORTA & 0x0F);


I've just been able to post my reply, what happened? :eek: I was able to read all topics and enter the CP, but could not reply or start a thread or PM anyone.
 
Last edited:
I've just been able to post my reply, what happened? I was able to read all topics and enter the CP, but could not reply or start a thread or PM anyone.
Ya even this was happening to me Last night.means some 6 hours ago.
 
However If I use an SPI ADC can I use the following code to get the conversion data from it.
Code:
int data;
for(i=0;i<=8;++i)
{
   output_high(PIN_B6);
   output_low(PIN_B6);
   shift_left(&data,1,input(PIN_B7));
}
Here B6 will be the clock and B7 the input data pin.
 
What you just posted there is a software SPI. That can use any pin combo you want, but its disadvantage is your code is stuck doing that work while in a hardware module it does it in the background... so to speak.

It looks like unless you find a way to remap the hardware SCK pin you'll have to use either software SPI or software parallel.

Take a look at which one you'll be using more (and its speed) and make the other as a software method.

Edit: As a side note, unless you need buffering, I would say software parallel is probably faster since its byte frame, not bit banged.
 
I use the CCS compiler myself, and one thing that you should consider is just letting the compiler handle software SPI. When you give the #use SPI command, specify whatever spare pins you have like this:

#use spi (DI=PIN_B1, DO=PIN_B0, CLK=PIN_B2, ENABLE=PIN_B4, BITS=16)

This will allow you to use spi on pins you have left over on any port, and the coding after this line will be identical. The only issue with doing it with software like this instead of using the PICs dedicated hardware is that it will be considerably slower, but should still be more than fast enough for a small LCD. For more info on this preprocessor directive see pages 124-125 of the CCS compiler manual.

One quick addition, with the compilers software SPI you also wont be able to use some (any?) of the SPI interrupts, all sends/receives from the software SPI will be blocking (ie no polling for received data, if you want to receive, you have to know when the data will be coming).
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top