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

dsPIC33F getting data from ADIS16209

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



Joined: 27 Jan 2010
Posts: 2

View user's profile Send private message

dsPIC33F getting data from ADIS16209
PostPosted: Wed Jan 27, 2010 1:01 pm     Reply with quote

Hello,

I am new to programming and I am trying to obtain the inclination data from ADIS16209 from analog device. Here is the code:

Code:


int HiByte;

void readADIS()
{
   _SPI1IP = 4;
   _SPI1IE = 1;
   _SPI1IF = 0;

   SPI1CON1bits.MSTEN = 1;
   SPI1CON1bits.MODE16 = 1;
   SPI1CON1bits.PPRE = 0;
   SPI1CON1bits.SPRE = 2;
   SPI1CON1bits.CKE = 1;
   SPI1CON1bits.CKP = 1;
   SPI1STATbits.SPIEN = 1;

   _LATB10 = 0;         // Set RB10 as CS pin         
   SPI1BUF = 0x0C;         // Accelerometer's register address
   _LATB10 = 1;
   
   _LATB10 = 0;
   HiByte = SPI1BUF;
   _LATB10 = 1;

   HiByte = (HiByte & 0b0011111111111111);       //Strip off the ND and EA flags   
}


I use the CRO and find that there is signal output from the CS pin and a clock pulse is also generated. However, there is still no response from the accelerometer and no signal can be received. Can anyone help?

here is the information of the Accelerometer:

http://www.analog.com/static/imported-files/data_sheets/ADIS16209.pdf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 27, 2010 1:17 pm     Reply with quote

This code is for the Microchip C30 compiler. This forum is for CCS
compilers. You should ask your question in one of the Microchip forums:
http://www.microchip.com/forums/
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jan 27, 2010 2:12 pm     Reply with quote

There are several errors in your code, these two are likely to cause transmission failure:
- Wrong SPI mode
- Writing command bytes to SPIBUF in 16-Bit mode doesn't send them in the first byte as required by the chip.
pietaL



Joined: 27 Jan 2010
Posts: 2

View user's profile Send private message

PostPosted: Wed Jan 27, 2010 10:19 pm     Reply with quote

Is the 33f supposed to be set to master mode? I have looked through the reference manual and the code for setting up is as follows:

Code:
/* The following code shows the SPI register configuration for Master mode */
IFS0bits.SPI1IF = 0; // Clear the Interrupt Flag
IEC0bits.SPI1IE = 0; // Disable the Interrupt
// SPI1CON1 Register Settings
SPI1CON1bits.DISSCK = 0; // Internal Serial Clock is Enabled
SPI1CON1bits.DISSDO = 0; // SDOx pin is controlled by the module
SPI1CON1bits.MODE16 = 1; // Communication is word-wide (16 bits)
SPI1CON1bits.SMP = 0; // Input data is sampled at the middle of data
// output time
SPI1CON1bits.CKE = 0; // Serial output data changes on transition
// from Idle clock state to active clock state
SPI1CON1bits.CKP = 0; // Idle state for clock is a low level;
// active state is a high level
SPI1CON1bits.MSTEN = 1; // Master mode Enabled
SPI1STATbits.SPIEN = 1; // Enable SPI module
SPI1BUF = 0x0000; // Write data to be transmitted
// Interrupt Controller Settings
IFS0bits.SPI1IF = 0; // Clear the Interrupt Flag
IEC0bits.SPI1IE = 1; // Enable the Interrupt


also, is it mean that i have to changed the register addrss to 0x0c00 but let the receive part ( HiByte = SPI1BUF ) remain unchanged?
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