_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?
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
Posted: Wed Jan 27, 2010 2:12 pm
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
Posted: Wed Jan 27, 2010 10:19 pm
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?
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