Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help in one PIC18F452,one accelerometer through spi interface

Status
Not open for further replies.

anilvadnala

New Member
Dear Frenz,

I am a student doing project work on PIC18f452.

PIC18f452 connect to a digital accelerometer through SPI interface.

As I am new to embedded and C I felt I made some mistakes in the start of C to read data from Accelerometer.

Below I am giving the data which I wrote..
Code:
#include<18f452.h>
#use delay (clock=6000000)
#use rs232 ( baud= 9600, xmit=PIN_C6, rcv= PIN_C7 )
#include<input.c>
#include<spi.h>
//#include<ACCL.h>
VOID main()
{
unsigned int a,b;
void spi_io(void);
{
setup_spi(spi_master, spi_slave)

CS=0                          //chip slect low to write to registers
                             //RE2=0
spi_write(0x0b)               // intiates write to control regb
                          //delay_us(130000)
spi_write(0x06)                // write operational mode byte to control regb
a=spi_read(0x8b)              //intiates the read from control reg b
CS=1
delay_us(130000)
spi_write(0x0a)               // intiates write to control regc
                      //CS=1
                     // delay_us(130000)
spi_write(0x00)                 //write operational mode byte to control regc
b=spi_read(0x8a)                //intiates the read from control reg c
CS=1
delay_us(130000)
//spi_write(0x06)
//delay_us(130)
//spi_write(0x14)
//delay_us(130000)
//spi_write(0x07)
//delay_us(130)
//spi_write(0x14)
//delay_us(130000)
//spi_write(0x08)
//delay_us(130)
//spi_write(0x0d)
//delay_us(130000)
//spi_write(0x09)
//delay_us(130)
//spi_write(0x14)
//CS=1                         //chip select high before
//delay_us(130000)
CS=0
// next step is conversion command

}
}

[code]

By following the instructions in the data sheet of Accelerometer I wrote this data the 13th page of data sheet given the above instructions and If any one find next conversion command please tell me and find mistakes from above data.

Advance thanks frens
 

Attachments

  • kxp841050 digital acc.pdf
    916.8 KB · Views: 306
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top