Spi interface with PIC

Status
Not open for further replies.

carapouet

New Member
Hello,

Since 3days I try to set up an interface between a PIC18F452 and a digital temperature sensor (TC72 or TC77, I have tested both).
I can send the commands to configure the config register but it still with the POR values.

First, I send 0x80 (to write the config register), then I send 0x04 (to set continuous temperature conversion).

Can you help me ? Do the commands I send are right ?
This is my code :
Code:
#include <p18f452.h>
#include <delays.h>
#include <spi.h>

#define SS PORTAbits.RA2

void init_pic(void);
void init_spi(void);

char i=1;

void init_pic(void)
{
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0x10;
ADCON1=0x06;
}
void init_spi(void)
{
SSPSTAT=0b01000000;
SSPCON1=0b00110001;
}

void main(void)
{
init_pic();
init_spi();
SS=1;

SSPBUF=0x80;
while(!PIR1bits.SSPIF);
SSPBUF=0x94;
while(!PIR1bits.SSPIF);
PORTB=SSPBUF;
SS=0;
while(1);
}

And two screenshots :
1° : my card : **broken link removed**
2° : my signals : **broken link removed**
green : CLK
red : SDO of the pic
blue : SS (chip enable)

Thanks
 

To start continous temperature conversion write 0x00 to 0x80. This clears all bits.
To do a one shot temperature reading write 0x10 to 0x80. This sets bit 4.

It is easy to get the bit numbers mixed up with the bit values. For example the value of bit 4 is 0x10. Rather then just using these values read the data sheet till they make sense. (Hey I could have muffed it).

3v0
 

Attachments

  • junk.gif
    21.6 KB · Views: 1,764
Hi,

Thanks for your reply.

I have tryied to write 0x00 in 0x80 :

Code:
SS=1;
SSPBUF=0x80;
while(!PIR1bits.SSPIF);
SSPBUF=0x00;
while(!PIR1bits.SSPIF);
PORTB=SSPBUF;
SS=0;

But the confi register still with 0x05 value :/

Maybe my commands are wrong ?
 
Last edited:
Can anyone help with hardware SPI ? I can not.

I can not help with hardware SPI, anyone ?

To date I have always used bit bang for SPI.

3v0
 

The Chip Select bit in SPI devices is active low.
 
I think that the TC77 is better suited for bit-banged SPI. If you have or want to use the MSSP of the PIC, the TC72 is a better choice because it has a true SPI interface.

EDIT: I've noticed the 'tcc' spec (CE to SCK Setup) in the datasheet of the TC72; at high clock frequencies (>10 MHz) you might try adding a short delay after setting the CE bit?
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…