Go to Post Some of us should be so lucky to have something go wrong on Einstein. - Kevin Sevcik [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-07-2010, 21:34
matrix_manshy matrix_manshy is offline
Registered User
no team
 
Join Date: Apr 2010
Location: egypt
Posts: 6
matrix_manshy is an unknown quantity at this point
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(" ");
}}
Reply With Quote
  #2   Spotlight this post!  
Unread 01-07-2010, 21:35
matrix_manshy matrix_manshy is offline
Registered User
no team
 
Join Date: Apr 2010
Location: egypt
Posts: 6
matrix_manshy is an unknown quantity at this point
Re: spi interface with accelerometer and pic 18f448 problem

i dont know problem of program as i think the code of read spi ao write spi is wrong
Reply With Quote
  #3   Spotlight this post!  
Unread 02-07-2010, 09:58
artdutra04's Avatar
artdutra04 artdutra04 is offline
VEX Robotics Engineer
AKA: Arthur Dutra IV; NERD #18
FRC #0148 (Robowranglers)
Team Role: Engineer
 
Join Date: Mar 2005
Rookie Year: 2002
Location: Greenville, TX
Posts: 3,078
artdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond repute
Re: spi interface with accelerometer and pic 18f448 problem

There are so many weird quirks with SPI that it will be almost impossible to find a perfect solution on the Internet.

I suggest that you get four things to solve your problem: an oscilloscope (preferably a digital one, as you can "pause" these), the accelerometer datasheet (especially the SPI timing diagrams), the microcontroller datasheet, and patience.

Try sending a sample data packet over the SPI bus. Hook up the SEL, CLK, MISO and MOSI lines to the oscilloscope. Watch the data packet being sent on the scope, and see if it looks like the timing diagrams. It could be something as simple as the SEL line goes active a half CLK cycle after the MOSI line starts sending data, throwing everything off. Or it could be much more complicated.

Debugging is a critical engineering skill, and it's one that can only be learned through lots of experience.
__________________
Art Dutra IV
Robotics Engineer, VEX Robotics, Inc., a subsidiary of Innovation First International (IFI)
Robowranglers Team 148 | GUS Robotics Team 228 (Alumni) | Rho Beta Epsilon (Alumni) | @arthurdutra

世上无难事,只怕有心人.
Reply With Quote
  #4   Spotlight this post!  
Unread 03-07-2010, 10:18
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: spi interface with accelerometer and pic 18f448 problem

Also, you might have a better chance of getting a response by posting in the SPI forum on Microchip; a bigger community of specifically PIC users means you'll have a better chance of finding someone who's had experience doing something similar with SPI on PIC, much less on the 18f448.

--Ryan
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
Reply With Quote
  #5   Spotlight this post!  
Unread 03-07-2010, 21:40
matrix_manshy matrix_manshy is offline
Registered User
no team
 
Join Date: Apr 2010
Location: egypt
Posts: 6
matrix_manshy is an unknown quantity at this point
Re: spi interface with accelerometer and pic 18f448 problem

thanks artdutra04 you make feel that i h as no hope as really i tired from spi interface and it's problems i will make the topic in spi forum thanks RyanCahoon
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ADXL345 SPI Accelerometer set/get Refnum Jon236 NI LabVIEW 3 16-02-2010 10:20
SPI interface for cRIO in C++?? Dale Programming 4 18-01-2010 20:15
Team 2102 Problem With Control Interface kevinbrice Control System 15 16-10-2009 23:56
More Problem With Accelerometer SamRI Electrical 6 01-02-2009 22:31
Software SPI Interface Greg Programming 11 08-02-2004 21:38


All times are GMT -5. The time now is 03:24.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi