CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

SPI between 18F4525 and TPIC8101

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

SPI between 18F4525 and TPIC8101
PostPosted: Tue Aug 09, 2005 11:38 pm     Reply with quote

Hi..I am trying to get SPI communication between 18F4525 and
a Knock Sensor IC from Texas Instrument TPIC8101.

I have tested a simple program to check whether it is
generating correct clock on SCK PIN or not. And it is working
correct.

After that I have written the following program to write five
command to TPIC8101 but could not get success. I have tried
the same program with many trial and error but no success.

Anybody worked on this chip previously...or
Can anybody guide me to get it working.....

Thanks..in advanced......

Quote:


#include <18F4525.h>
#fuses H4,NOWDT,NOPROTECT,NOLVP,BROWNOUT,PUT,NOPBADEN,NOXINST,NOMCLR
#use delay(clock=40000000) // 40 MHz
//===========================

//With respect to Knock Sensor
#define CHIP_SELECT PIN_C6 //for CS
#define INT_HOLD PIN_C7 //SCK

int1 LEDOn=0;

void main()
{

set_tris_c(0x00);

output_low(INT_HOLD); //disable any SPI transmission

//setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4);

output_low(CHIP_SELECT);

spi_write(0x48);

spi_write(0xE0);

spi_write(0x30);

spi_write(0xB1);

spi_write(0x8F);

output_high(CHIP_SELECT);

output_high(INT_HOLD); //disable any SPI transmission

set_tris_a(0x01);

setup_adc_ports(AN0);
output_high(PIN_A3);

while(1) // LED testing
{
if(LEDON==0)
{
output_high(PIN_A3); //LED On

LEDOn=1;
}
else
{
output_low(PIN_A3); //LED Off
LEDOn=0;
}

delay_ms(100);

}

}


asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Aug 09, 2005 11:45 pm     Reply with quote

Quote:
spi_write(0x8F);

output_high(CHIP_SELECT);

output_high(INT_HOLD); //disable any SPI transmission


The SPI requires a finite amount of time to serialize the data out the port. After you have performed your last write to the SPI port you immediately disable the chip select on the target. For most targets this will reset comms.

When you initially enabled the chip select did you ensure you met the setup times before the first bit is serialized to the target device?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 12:04 am     Reply with quote

Actually the timing is in neno sec and time for executing one instruction
is 0.1us which is enough. I have tried to put delay over there as well.

I have tried to make Chip Select low and high for each command
individually.

I can't understand what is going on and what is not?
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Aug 10, 2005 12:39 am     Reply with quote

You are driving the SPI clock too fast. The maximum the texas chip will support is 5MHz and you are driving it at 10MHz.

I just looked at the code produced by the compiler in your other thread. I see that the PIC waits for a BF true condition before movig onto the next instruction. It is using the SPI BF flag to indicate that the SPI has finished serializing out the last bit of the current byte. According to the data sheet for the PIC the BF flag is only relevant in receive mode but this is obvioulsy not the case.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!


Last edited by asmallri on Wed Aug 10, 2005 12:59 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 12:57 am     Reply with quote

Quote:

spi_write(0x48);
spi_write(0xE0);
spi_write(0x30);
spi_write(0xB1);
spi_write(0x8F);

You have command No. 5 set to 0x8F.
But the data sheet shows that the upper 3 bits of command No. 5 are 110.
So the upper nybble has to be either 0xC or 0xD. It can't be 8.
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 8:42 pm     Reply with quote

I have changed the above mentioned changes but could not get the
success. I have read the datasheet for TPIC8101 many times. And
also read the SPI in the 18F4525 deatasheet but I don't know, what
going wrong? I can't think after this.

Anybody have experience of this kind of things then please guide me.

Here with I am sending the code that I am using. I have tested the same
code with lots of different diffrent trials.

Quote:


#include <18F4525.h>
#fuses H4,NOWDT,NOPROTECT,NOLVP,BROWNOUT,PUT,NOPBADEN,NOXINST,NOMCLR
#use delay(clock=40000000) // 40 MHz
//===========================

//With respect to Knock Sensor
#define CHIP_SELECT PIN_C6 //for CS
#define INT_HOLD PIN_C7 //SCK
#define KNOCK_CLK PIN_C3 //SCK

int1 LEDOn=0;

void main()
{


set_tris_c(0x00);

output_low(INT_HOLD); //disable any SPI transmission
output_low(KNOCK_CLK);

setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
//setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);

output_low(CHIP_SELECT);

output_low(CHIP_SELECT);
spi_write(0x48); //Set the prescaler and SDO status
output_high(CHIP_SELECT);

delay_us(1);

output_low(CHIP_SELECT);
spi_write(0xE0); //Select the channel
output_high(CHIP_SELECT);

delay_us(1);

output_low(CHIP_SELECT);
spi_write(0x18); //Set the band-pass center frequency
output_high(CHIP_SELECT);

delay_us(1);

output_low(CHIP_SELECT);
spi_write(0x98); //Set the gain
output_high(CHIP_SELECT);

delay_us(1);

output_low(CHIP_SELECT);
spi_write(0xD8); //tried 0x98 //Set the integration time constant
output_high(CHIP_SELECT);

delay_us(10);

output_high(CHIP_SELECT);

output_high(INT_HOLD); //disable any SPI transmission

set_tris_a(0x01);

setup_adc_ports(AN0);
output_high(PIN_A3);

while(1)
{
if(LEDON==0)
{
output_high(PIN_A3);

LEDOn=1;
}
else
{
output_low(PIN_A3);
LEDOn=0;
}

delay_ms(100);

}

}



Last edited by prayami on Wed Aug 10, 2005 9:57 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 9:27 pm     Reply with quote

Quote:
I have changed the above mentioned changes but could not get the success


What is your definition of "success" in this project ?
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 10:12 pm     Reply with quote

Hi..PCM Programmer....
I have added comments against all the five commands about what
purpose they mean to be.

The success in this project means: If above five commands are
successfully written to the TPIC8101 then the chip should work
like following.

As I have set following by five commands
Prescaler : 10Mhz (This is input clock I am applying at PIN XIN)
Select channel: 1
Bandpass Centre frequency: 3.28KHz
Gain: 0.63
Integrator Constant: 320

I am applying input frequency on PIN CH1N as mentioned in the
datasheet. And checking the output on OUT PIN.

The chip should allow the frequency to pass nearer to Bandpass centre
frequency. And show some analong voltage output on PIN OUT as knock.

I can see that the OUT PIN is being high all the time no matter what
ever is the input frequency and what ever is the amplitude of the
input signal. I have tried all frequency range but there is no change
on the OUT PIN.

I am still not sure whether the five commands are written successfully in
the TPIC8101 chip or not? I don't know what are the things those I should
try alternatively to test. And what to do next...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 10:46 pm     Reply with quote

In the TPIC8101 data sheet, there are two timing diagrams:
Figure 3 and Figure 4.

They show the INT/HOLD signal as high for 1000 us and low for 1500 us.
In your code, you always have it either high or low constantly.
You need to change it to look like the data sheet. Then look at the
output pin with an oscilloscope.

Add the following while() loop to the end of your code
(get rid of the LED loop) like this:
Code:

while(1)
  {
   output_high(INT_HOLD);
   delay_us(1000);
   output_low(INT_HOLD);
   delay_us(1500);
  }
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

PostPosted: Thu Aug 11, 2005 7:11 pm     Reply with quote

Thanks PCM Programmer...your idea works
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group