Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | 68HC12 | Senior design project

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

Senior design project - maram_aljishi - Mar 23 17:46:59 2009

Hello all,
I am working on my senior design project ( American University of Sharjah), and part of it is interfacing an accelerometer to the HC12 using SPI.
I have connected the cct correctly however I am not getting any output, and I was if anyone can help me with the code. I would appreciate any help please
Here is the code :
#include
#include
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;
init_lcd();
clr_disp();
while (1)
{

DDRM |= BIT1;/* configure the PM1 pin for output */
//DDRM = 0xFF;
PTM &= ~BIT1;
openspi0(); /* configure SPI0 module */
putcspi0(0x0F);// write address of the reg in the accelerometer
m=getcspi0();
num=m;

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

}
}
and here is the 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 */
}

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )