Search the web
Sign In
New User? Sign Up
gnu-m68hc11 · GNU 68HC11/HC12
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
SPI interface   Message List  
Reply | Forward Message #9303 of 9422 |
Hello,
I am a computer engineering student, an I am working on my senior year project.
I am trying to connect an accelerometer to the HC12 using the SPI
However I am not getting any readings
Can anyone please help me or at least tell me ways to debug it

here is the code>
#include <D12_LCD.h>
#include <spi0util.c>
void openspi0(void)
{
SPI0BR = 0x30; /* set baud rate to 6 MHz */
SPI0CR1 = 0x50;
SPI0CR2 = 0x02;
WOMS = 0x00; /* enable Port S pull-up */
}
void main(void)
{
char m;
int num;
int num2;
init_lcd();
clr_disp();
while (1)
{

//DDRM |= BIT1;/* configure the PM1 pin for output */
DDRM = 0xFF;
PTM &= ~BIT1;
openspi0(); /* configure SPI0 module */
putcspi0(0x0F);
m=getcspi0();
num=m;
//num2=num & 0x0F;
//num= (int ) m;

lcd_print_txt("I am: ",LINE1);
//put_char(m);

lcd_print_val(num);
}
}



header file:
/*******************************************************************************\
******/
/* The following function outputs a character to the SPI0 interface.
*/
/*******************************************************************************\
******/
void putcspi0 (char cx)
{ char temp;
while(!(SPI0SR & SPTEF)); /* wait until write is permissible */
SPI0DR = cx; /* output the byte to the SPI */
while(!(SPI0SR & SPIF)); /* wait until write operation is complete */
temp = SPI0DR; /* clear SPIF flag */
}
/*******************************************************************************\
*****/
/* The following function outputs a string to the SPI0 interface.
*/
/*******************************************************************************\
*****/
void putsspi0(char *ptr)
{
while(*ptr) { /* continue until all characters have been output */
putcspi0(*ptr);
ptr++;
}
}
/*******************************************************************************\
*****/
/* The following function reads a character from the SPI0 interface.
*/
/*******************************************************************************\
*****/
char getcspi0(void)
{
while(!(SPI0SR & SPTEF)); /* wait until write is permissible */
SPI0DR = 0x00; /* trigger 8 SCK pulses to shift in data */
while(!(SPI0SR & SPIF)); /* wait until a byte has been shifted in */
return SPI0DR; /* return the character and clear SPIF flag */
}
/*******************************************************************************\
*****/
/* The following function reads a string of count bytes from the SPI interface.
*/
/*******************************************************************************\
*****/
void getsspi0(char *ptr, char count)
{
while(count) { /* continue while byte count is nonzero */
*ptr++ = getcspi0(); /* get a byte and save it in buffer */
count--;
}
*ptr = 0; /* terminate the string with a NULL */
}


Thank you




Mon Mar 23, 2009 3:36 pm

maram_aljishi
Offline Offline
Send Email Send Email

Forward
Message #9303 of 9422 |
Expand Messages Author Sort by Date

Hello, I am a computer engineering student, an I am working on my senior year project. I am trying to connect an accelerometer to the HC12 using the SPI ...
maram_aljishi
Offline Send Email
Mar 23, 2009
3:43 pm

Maram, which accelerometer are you using? note that each IC might have especific SPI requirements like Mode of Communication (phase of clock for valid data)...
ovolpato
Offline Send Email
Mar 23, 2009
4:52 pm

... The #1 suggestion I can make for you is, if you have access to a scope, use it. Check the signals at the actual pins and make sure you are in fact getting...
Stephan Rose
kermos2000
Offline Send Email
Mar 23, 2009
11:27 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help