View previous topic :: View next topic |
Author |
Message |
Birdasaur
Joined: 07 Oct 2003 Posts: 29
|
Example for a TC77? |
Posted: Fri Dec 12, 2003 6:38 am |
|
|
Does anyone out there have a bitbang or SPI_READ() example for a TC77? I've tried the CCS spi_read() calls, but they clock 8 bits, whereas the TC77 temperature register is a 13 bit register. Needless to say a simple read isn't helping me. I've also tried to do a simple bit bang, but its not working. In fact, I can't seem to get the TC77 to even respond using the bit bang. I've posted this question in another thread but it is not getting viewed. I thought maybe it deserved its own thread.
here's some code that DOES NOT WORK
//to try to bit bang the 13 bits
output_low(PIN_B1); //select the TC77
for(i=13; i>0; i--)
{
delay_us(10);
output_high(PIN_B2);
delay_us(10);
if (input(PIN_B3))
bit_set(data,i);
delay_us(10);
output_low(PIN_B2);
delay_us(10);
}
output_high(PIN_B1); //deselect the TC77
This code also fails
//To use the spi_read() function
output_low(PIN_B1); //select the TC77
temp1 = spi_read(0x00); //Read the 8 MSB of the data
temp2 = spi_read(0x00);
output_high(PIN_B1); //deselect the TC77
For the SPI_READ() code I've tried all manner of combinations of reads and writes and all return goofy results. I must be missing something simple, could somebody out there just point me back in the right direction? |
|
|
Birdasaur
Joined: 07 Oct 2003 Posts: 29
|
:grin: The Solution |
Posted: Fri Dec 12, 2003 8:35 am |
|
|
Here's the code that works like a dream. Turns out I had a couple jumpers interfering with my bitbang lines. (duh )
Also I had the clock order wrong, gotta lower the clock, than raise the clock BEFORE the data bit is clocked out.
I don't know how much of each delay is needed.
while(1)
{
delay_ms(1000);
data = 0;
F = 0;
output_low(PIN_B1); //select the TC77
for(i=13; i>0; i--)
{
output_high(PIN_B2); //clock
delay_us(10);
output_low(PIN_B2);
delay_us(10);
if (input(PIN_B3))
bit_set(data,i);
}
output_high(PIN_B1); //deselect the TC77
data >>= 6; //to get rid of the fraction of a degree
F = (unsigned int16) (1.8 * data) +32;
printf("\r\nThe temperature is: %lu C/%lu F \r\n",data,F);
}
Good luck to everyone, I hope this helps someone. |
|
|
wedilo
Joined: 16 Sep 2003 Posts: 71 Location: Moers, Germany
|
|
Posted: Mon Dec 15, 2003 2:58 am |
|
|
Hi Birdasaur,
fine code snippet. Thank you...
BUT, in your first post you ask for some code and in your second post you give the answer yourself? Amazing...
73 Sven |
|
|
Birdasaur
Joined: 07 Oct 2003 Posts: 29
|
well.... |
Posted: Mon Dec 15, 2003 10:17 am |
|
|
I try to contribute to the forum whenever I can. I've asked for a lot of help in the past and I want to be the "helper" too.
Also, noone answered me so I figured it was a mystery.
It was easier than I thought too.
Good luck everyone.
|
|
|
wedilo
Joined: 16 Sep 2003 Posts: 71 Location: Moers, Germany
|
|
Posted: Tue Dec 16, 2003 1:50 am |
|
|
Hello Birdasaur,
that's a great attitude.
Thank you and all the best
73 Sven |
|
|
>>TechDesign Guest
|
tc77 |
Posted: Sun Jun 20, 2004 7:38 am |
|
|
this one works too! (on a 16f877)
i took these non-standard pins, cause i need RC3 & RC4 for i?c routines..
Code: | #bit TC77_CS =pb.7 // RB7 pin40,TC77 !CS
#bit TC77_SIO =pb.6 // RB6 pin39,TC77 S I/O
#bit TC77_SCK=pb.5 // RB5 pin38,TC77 SCK
...
...
void tc77_read(void);
int16 t_in;
...
...
void main(){
tris_pb=0x51; // oiox xxxx
TC77_CS=1; //
while(1)
{
tc77_read();
lcd_gotoxy(90,0); // my own routines to display t_in
printf(lcd_text,"%lx",t_in); // id.
delay_ms(100);
} //end while
} //end main
void tc77_read(){
char b;
t_in=3;
TC77_SCK=1;
TC77_CS=0;
for(b=16;b!=2;b--){
TC77_SCK=0;
TC77_SCK=1;
if (TC77_SIO){
bit_set(t_in,b-1);
}
}
TC77_SCK=0;
TC77_CS=1;
} |
// so there's no need for long delays at all!! But please do put an elco of 10?F/16V AFTER the voltage regulator. The AD-conversion inside the TC77 needs it!! |
|
|
|