question about the pin to pin connections on a SPI interface


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Default question about the pin to pin connections on a SPI interface

    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.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    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.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    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.

  4. #4
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    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.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    Code:
    '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
    Code:
    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
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    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?

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    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.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    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?

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    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.
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: question about the pin to pin connections on a SPI interface

    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.

Similar Threads

  1. Need to use SPI but I'm already using the SPI port
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th December 2012, 09:52
  2. 5v on analog pin but reads value
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 9th November 2012, 03:41
  3. VFD pinout and connections
    By rshaver in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 26th October 2010, 05:48
  4. lcd with Hserout and a max232 connections? help
    By flipper_md in forum Schematics
    Replies: 6
    Last Post: - 8th March 2008, 15:06
  5. PIC to PIC, How Many IO Connections Required?
    By CocaColaKid in forum Serial
    Replies: 4
    Last Post: - 1st September 2005, 17:16

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts