Communication between SCA3000 and PIC16F877A

Have you got the greatest 48 bit multiplier ever conceived? Prove it - post your code here.

Moderator: phalanx

Post Reply
brunocae
Posts: 3
Joined: Tue Dec 28, 2010 12:08 pm

Communication between SCA3000 and PIC16F877A

Post by brunocae » Tue Dec 28, 2010 1:07 pm

Hi,

I'm trying to make SPI communication between SCA3000 accelerometer and PIC16F877A, and I'm programming on MikroC IDE, from Microchip. I made a simple code, that reads x-axis acceleration data from the sensor, and shows it on a LCD 16x2 Display, but it doesn't work. All I get is "0". Here is my code:

Code: Select all

// ========== Initial Declaration ==========
unsigned char LCD_text[10];
unsigned short buffer;

unsigned short X_MSB, X_LSB;
int x_axis;

// ========== main() function ==========
void main()
{
// ---> Ports' Initialization
TRISA = 0b000000;
TRISB = 0b00000000;
TRISC = 0b00010000;
ADCON1 = 0b00000111; // just to turn off A/D converter

// ---> LCD Initialization
Lcd_Config(&PORTB,4,5,6,3,2,1,0);
Lcd_Cmd(Lcd_CURSOR_OFF);

// ---> SPI Initialization
PORTA.F5 = 1; // Chip Select = 1
Spi_Init_Advanced(MASTER_OSC_DIV4, DATA_SAMPLE_END, CLK_Idle_HIGH, LOW_2_HIGH);

// ---> SCA3000 Initializes on measurement mode by defaut
Delay_ms(500); // Waits for SCA3000

// ---> SPI Communication Loop
while(1)
{
PORTA.F5 = 0; // Chip Select = 0
Spi_Write(0b00010100); // Register Address (0x05 = 0b000101) + Read bit(0) + 0
X_MSB = Spi_Read(buffer);
Spi_Write(0b00010000); // Register Address (0x04 = 0b000100) + Read bit(0) + 0
X_LSB = Spi_Read(buffer);
PORTA.F5 = 1; // Chip Select = 1

x_axis = (X_MSB<<8)+(X_LSB);

IntToStr(x_axis,LCD_text); // Convert it into string and show on LCD
Lcd_Out(1,1,LCD_text);

Delay_ms(500);
Lcd_Cmd(LCD_CLEAR);
}
}
Can anyone help me find what's wrong in my code??
thanks.

royf
Posts: 1
Joined: Tue Dec 28, 2010 2:15 pm

Re: Communication between SCA3000 and PIC16F877A

Post by royf » Tue Dec 28, 2010 2:18 pm

Hi,

It's been a while since I have done any coding with SPI but i'm sure after every byte sent I had to do a dummy read?

waltr
Support Volunteer
Posts: 2823
Joined: Tue Sep 08, 2009 12:07 pm
Location: Philadelphia, USA

Re: Communication between SCA3000 and PIC16F877A

Post by waltr » Tue Dec 28, 2010 2:39 pm

Duplicate post!
See my response here:
viewtopic.php?f=14&t=25371

Post Reply