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

dsPIC33 SPI interface with external ADC

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



Joined: 19 Jul 2013
Posts: 10

View user's profile Send private message

dsPIC33 SPI interface with external ADC
PostPosted: Mon Sep 30, 2013 11:57 am     Reply with quote

Hi there,

I am using a dsPIC33FJ64GS606 to interface with an external ADC (Texas Instrument's ads1281). I am using the SPI module on the dsPIC33 to interface with the ADC. As of now, I would just like to be able to set the dsPIC33 as the Master, and the ADC as the slave. I am trying to establish a serial clock for the ADC of 648kHz. Using an external oscillator and the on board PLL, I am running a 72.576MHz clock on the dsPIC33, and I am implementing the SPI_CLK_DIV_112 to step down the
frequency to 648kHz for the ADC.

The external oscillator (which operates at 2.592 MHz) is also hooked to the CLK pin (pin 1) on the ADC, and the frequency has been verified (via Oscope). As of right now, I can ONLY see the clock signal for the CLK pin on the ADC, I cannot get the SCLK pin (pin 2) on the ADC to receive the master signal from the dsPIC33. Not only that, I cannot get the dsPIC33 to generate the Master SCLK signal from it's own sCLK pin (PIN_G6), I have checked both with an Oscope.

For the SPI module on my dsPIC33, SCK2 = PIN_G6, SDI2 = PIN_G7, and SDO2 = PIN_G8 (although SD02 is not connected to anything, we designed the board that way because we are only reading values into the SPI module).

So far, I have tried the following trouble shooting methods with no success:

I used the getenv("SPI") function to ensure that the device has an SPI module (even though I already knew this, I did it for sanity's sake).
getenv("SPI") returned true, so the SPI Module was detected, and the pin toggled.
Code:

      int8 spiVal = getenv("SPI");
      if (spiVal == TRUE) {
         output_high(PIN_F5);
         delay_us(100);
         output_low(PIN_F5);
      }

Next, I wanted to see if the SCK2 pin was broken, so I wrote a test program to toggle that pin. I was able to toggle the pin just fine (checked with an Oscope).
Code:

   while(1) {
         output_high(PIN_G6);
         delay_us(100);
         output_low(PIN_G6);
      }

I would design a test program to see if I can write out of the SPI, however the SDO2 pin is not connected and the board is not easily modifiable.

As for my hardware/compiler I am using the ICD-U64 debugger, firmware version 2.95. I am using the CCS IDE and compiler, v4.134. As stated above, I am using the dsPIC33FJ64GS606, with the Texas Instruments ads1281 ADC.

Here is my code setting up the SPI module, I am hoping that I cannot get the SCLK to run because of a settings code error or something of the like, any help is greatly appreciated.
Code:

#INCLUDE <33FJ64GS606.h>   //Library for the dsPIC MPU
#DEVICE ICD=3              //ICD Debugger through PGD3/PGC3 Pins
#FUSES NOWRT               //Program memory not write protected
#FUSES NOWRTB              //Boot block not write protected
#FUSES EC                  //Crystal Oscillator @ 2.592MHz
#FUSES NOWDT               //No Watch Dog Timer
#FUSES NOPUT               //No Power Up Timer
#FUSES NOJTAG              //JTAG disabled
#FUSES PR_PLL              //Primary Oscillator w/ PLL

#USE delay(oscillator=2.592MHz, clock=72.576MHz)  //External Crystal Oscillator @ 2.592MHz w/ PLL for 72.576MHz

void main() {
   setup_spi2(SPI_MASTER | SPI_CLK_DIV_112);
   while (1);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Sep 30, 2013 1:15 pm     Reply with quote

Nothing will appear on the SPI clock, till you send data.
SPI sends a clock for each bit of the data you send. It doesn't send a clock, when no data is being sent.

Best Wishes
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