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.

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
 
junk-gif.26420

At power-up, the SHDN bit is set to ‘1’. Thus, the TC72
is in the shutdown operating mode at startup. The Continuous
Temperature Conversion mode is selected by
writing a ‘0’ to the SHDN bit of the Control register.
...
The One-Shot mode is selected by writing a ‘1’ into bit
4 of the Control register.
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
    junk.gif
    21.6 KB · Views: 1,761
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:
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 ?

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.

New Articles From Microcontroller Tips

Back
Top