Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 19th October 2007, 09:50 PM   (permalink)
Question Both parallel and spi in PIC microcontroller PLEASE HELP

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 is offline  
Old 19th October 2007, 10:01 PM   (permalink)
Default

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
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now  
Old 19th October 2007, 10:12 PM   (permalink)
Default

Quote:
Originally Posted by jitun2
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 by eng1; 19th October 2007 at 10:23 PM.
eng1 is offline  
Old 20th October 2007, 05:38 AM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
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.
jitun2 is offline  
Old 20th October 2007, 08:40 PM   (permalink)
Smile

Quote:
Originally Posted by eng1
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.
jitun2 is offline  
Old 20th October 2007, 11:15 PM   (permalink)
Default

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? I was able to read all topics and enter the CP, but could not reply or start a thread or PM anyone.

Last edited by eng1; 20th October 2007 at 11:31 PM.
eng1 is offline  
Old 21st October 2007, 05:17 AM   (permalink)
Default

Quote:
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.
jitun2 is offline  
Old 21st October 2007, 05:19 AM   (permalink)
Default

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.
jitun2 is offline  
Old 22nd October 2007, 11:50 PM   (permalink)
Default

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.
iso9001 is offline  
Old 23rd October 2007, 01:39 AM   (permalink)
Default

Or use a 18F4550 and you get a complete 8 bit port RD.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now  
Old 23rd October 2007, 04:23 AM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
Or use a 18F4550 and you get a complete 8 bit port RD.
Ya it will be better to use a PIC18F4550.
jitun2 is offline  
Old 23rd October 2007, 07:45 PM   (permalink)
Default

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 by Stellarcore; 23rd October 2007 at 07:48 PM.
Stellarcore is offline  
Old 24th October 2007, 03:08 PM   (permalink)
Default

Thank you guys for you help.But finally i decided to use PIC18F4550
jitun2 is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 09:33 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker