|
spi interface with accelerometer and pic 18f448 problem
hi i am new user to microcontroller and accelerometer adxl345 i have a great problem in interfacing the spi of picadxl345 and pic 18f448 as i want to write to an addresses of registers inside the accelerometer with special data to be configured to read displacemmment "after double integeration" i have a great problem in in how to differentiate between the data and adress as in the accelerometer datasheet there are 2 bit in begining of address (1 for read ,o for write ) and other bit used for multiple bit and then 6 bit address and data 8 bit what i want to know if i can make both by write spi after each other only and after them what to start new transmission ? and other i dont know if i set bit 1 for read i enter as example char x=readspi() only after it ?
last question and i am sorry for long question is to configure uart from output of spi to be at out put i want to see an example of this case please because really i am in great troouble as my graduation project presentation in less than 2 weeks
#include <p18f448.h>
#include <usart.h>
#include <delays.h>
#include<stdlib.h>
#include<stdio.h>
#include <spi.h>
#define SPI_CS LATBbits.LATB0
char x,y[2],o;
int m;
void delay (void)
{
int i;
for (i = 0; i < 3500; i++)
;
}
void delay1 (void)
{
int i;
for (i = 0; i < 1000; i++)
;
}
void delay2 (void)
{
int i;
for( i=0;i<=366;i++);
}
void main (void)
{
OpenSPI(SPI_FOSC_16, MODE_00, SMPEND);
OpenUSART(USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,92);
TRISB=0x00;
while(1){LATBbits.LATB0=0b0;
WriteSPI(0x6D); // adress of accelerometer
WriteSPI(0x01); //data
Delay10KTCYx( 50 );
LATBbits.LATB0=0b1;
Delay10KTCYx( 20 );
LATBbits.LATB0=0b0;
WriteSPI(0xED);//to enable write bit
o=ReadSPI();
LATBbits.LATB0=0b1;
m=o; // to convert to integer
itoa(m,y);//to be read by uart
putrsUSART("id");
putrsUSART(" ");
putsUSART( y);
putrsUSART(" ");
}}
|