PDA

View Full Version : question about the pin to pin connections on a SPI interface



wdmagic
- 3rd January 2013, 04:24
http://imageshack.us/photo/my-images/8/cicuit2.gif/

I've got alot of these thermalcouple chips and ive got plenty of thermalcouples. I would like to interface them with a 18f4550, i have never used a SPI device or I2C, the link above is a sample pic circuit that uses my particular temprature chip. but uses another PIC. Im assuming you just use some serial in code but i dont understand the electrical connections, the pin names dont match? is there a chart somewhere that has put pin a to slot b? I assumed SDO -> SDO and such. if anyone has an article on using the SPI funtion with schematic and reasons for what pin goes to what i would be grateful.

mackrackit
- 3rd January 2013, 11:17
Use the I2C command and you will be able to use just about any pin. Otherwise you will have to use the pins specified in your chips data sheet.

peterdeco1
- 3rd January 2013, 17:21
Hello wdmagic. I use a different chip but I think the principle will be the same.

Low PORTA.3 : Pause 1 'CHIP SELECT
ShiftOut PORTC.5,PORTC.3,0,[YOUR DATA\16]
'PORTC.5 IS MASTER OUT SLAVE IN (MOSI), PORTC.3 IS SCLK
High PORTA.3 : Pause 1 'deselect - end of word

'use your data\16 for word variable or \8 for byte variable
the 0 after portc.3 sends LSB first or use 1 for MSB first
Hope this helps.

wdmagic
- 4th January 2013, 00:34
ok that was way over my head, first it sounded like you have my PIC sending commands out, however this is a thermostat chip sending data to my PIC, there is no control that i have seen it just streams data out over and over from what i can tell. So I think im supposed to use a shiftin? as that was the only word i recognized all the rest of what you said lost me. I can build the circuit just as they have it in the picture, thankfully they have a resolution high enought for me to read the pinouts, but i could use some help on the code for that particular circuit, with the only change being that the chip I am using is a 18f4550. I did find a article that said the SDO should go to SDI and vice versa, but other than that Im lost.

mackrackit
- 4th January 2013, 10:37
'Alias pins - MAX6675 temp sensor
MXSCLK VAR PORTA.0 'Clock
MXCS VAR PORTA.1 'Chip Select
MXSO VAR PORTA.2 'Serial out
TRISA =%00000000
DEFINE SHIFT_PAUSEUS 100
ADCON1 = 15 ' All I/O pins digital
CMCON = 7
TRISD =%00000000
'Allocate MAX6875 Variables
MXTemp VAR WORD 'raw data from 6675/type K sensor
TempC VAR WORD 'BYTE[16] 'converted to degrees C
TempF VAR WORD



READ_TEMP:
MXCS = 0 'Chip select low
shiftin MXSO, MXSCLK, 0, [MXTemp\16] 'read the data to MXTemp
MXCS = 1 'Chip select high
TempC = MXtemp >> 5 'right shift the data 5 places to get degrees C (Read the Data sheet)
TempF = ABS(TempC) */ 461
TempF = TempF + 32

wdmagic
- 4th January 2013, 11:41
ok so the chip select goes low and tells the temprature chip to send data, it reads data into mxtemp variable then chip select goes high releasing the temprature chip then does the conversion?

I didnt know you had to send a signal to the temp chip to tell it to send data to the pic, i figured it just kept sending data over and over and the pic just grabed the first set of data that was a full string of data with a start and stop bit type of thing.

however im a bit confused, you set port A to all outputs, A.2 is set as output but wouldnt you want that to be the serial in and be an input?

I read up on the shiftin command but it doesnt say if the port needs to be an input or output port. can you clarify this?

also in this code
TempF = ABS(TempC) */ 461
TempF = TempF + 32
i see absolute of tempc, but what is this */461?
I use another formula for converting C to F
My original code for conversion was

ANA0 = ANA0 / 13 'Convert 16bit to 10bit (65k = 5k)
TEMP = (((ANA0 / 10) * 9) / 5) + 33 'Convert ANA0 to Farent.

but I have changed it now to

TEMP = ((((TEMP / 10) * 9) / 5) / 13) + 32 'Convert ANA0 to Farent.
this works better and is alot more acurate since it does the math with large numbers and then reduces it.
however this is the code I use for converting a ADC line not if i have the Celcius number to begin with
So what does */461 do?

mackrackit
- 4th January 2013, 12:07
SHIFTIN/SHIFTOUT are commands that will change the TRIS on the fly as needed, so I just set the TRIS as 00000000 and let PBP take care of it.



this works better and is alot more acurate since it does the math with large numbers and then reduces it.
however this is the code I use for converting a ADC line not if i have the Celcius number to begin with
So what does */461 do?

How do you know if one is better than the other if you do not understand how one of them work?

Look in the PBP manual chapter 4 if you are using pre PBP3, chapter 3 if you are using PBP3. It does a good job of explaining it.

wdmagic
- 4th January 2013, 12:32
shiftin/out is in chapter 5 of my manual, version 2.6, it explains a lttle better, your code for the conversion of the temprature looks better but I dont understand that */461 part, since it doesnt have a name for that i cant find it in the book, its like another part of code i saw yesterday that had a !! in part of it, how do you find */ or !! in the manual :)

Oh, meant to ask, ive seen notations that say you can use several SPI devices on 1 PIC, would you tie all the Data lines together and then just use one I/O for each chip select? so 4 temp chips would use 4 I/O (chip selects) but only 1 clock and serial data pins?

mackrackit
- 4th January 2013, 12:37
how do you find */ or !! in the manual

Look in the PBP manual chapter 4 if you are using pre PBP3, chapter 3 if you are using PBP3. It does a good job of explaining it.



Oh, meant to ask, ive seen notations that say you can use several SPI devices on 1 PIC, would you tie all the Data lines together and then just use one I/O for each chip select? so 4 temp chips would use 4 I/O (chip selects) but only 1 clock and serial data pins?

You can share everything except the data line.

wdmagic
- 4th January 2013, 13:03
ok I found it, I kind of understand it but ive been up way to long and its hard to focus on it, ive got to get in bed for a few hours. Ill try it out it sounds pretty good. thanks.