/******************************************************************************************/
/* Company : Cobra Automotive Technologies */
/* Author : A.C. */
/* Module name : spi1.c/.h */
/* Module version : 0.0 */
/* Module description : SPI 4-wire bus driver that uses ISR only for data receiving */
/* Platform : Freescale MC9S08AW16 */
/* Notes : */
/* */
/* */
/* --- Module History --------------------------------------------------------------------*/
/* */
/* --------------------------------------------------------------------------------------*/
/* | Date | Ver. | Author | Notes | */
/* |------------|---------|----------------|--------------------------------------------| */
/* | 16/02/2010 | 0.0 | A.C. | First version | */
/* |------------|---------|----------------|--------------------------------------------| */
/* | | | | | */
/* |------------|---------|----------------|--------------------------------------------| */
/******************************************************************************************/
#define __SPI1_PRIVATE__
/*
********************************************************************************
* Header/include files *
********************************************************************************
*/
#include "MC9S08AW16.h" /* */
#include "io.h"
#include "spi1.h"
/*
*******************************************************************************
* *************************************************************************** *
* * PROTECTED FUNCTION DEFINITION (ISR routines) * *
* *************************************************************************** *
*******************************************************************************
*/
/*
********************************************************************************
* Function name : SPI1_Interrupt() *
********************************************************************************
* Author : Alessandro Cervellin *
* Input parameters : none *
* Return value : none *
* Function description : puts the received data byte into the buffer *
* Notes : *
* *
* --- Function History ------------------------------------------------------- *
* *
* -------------------------------------------------------------------------- *
* | Date | Notes | *
* |----------|---------------------------------------------------------------| *
* |S 16/02/10| Base Relesase | *
* |E 16/02/10| | *
* |----------|---------------------------------------------------------------| *
* | | | *
* -------------------------------------------------------------------------- *
* *
* --- Open issues ------------------------------------------------------------ *
* *
********************************************************************************
*/
@interrupt void SPI1_Interrupt(void)
{
UC_8 t;
// while (SPI1_SPSCK); /*wait for clock to return low (no default)*/
while (!SPI1_SPSCK); /* wait the return to High*/
t = SPI1S; /* Acknowledge flags */
Spi1_RxBuffer[Spi1_RxBufferIdx] = SPI1D; /* Get the data */
Spi1_RxBufferIdx++;
if (Spi1_RxBufferIdx > Spi1_RxDataToReceive) {
Status = SPI_RD_COMPLETED;
}
}
/*
*******************************************************************************
* *************************************************************************** *
* * PRIVATE FUNCTION DEFINITIONS * *
* *************************************************************************** *
*******************************************************************************
*/
void Spi1_Delay10us(void){
UC_8 i;
for (i=5; i>0; i--){
#asm // 4 x Nop() = 1us
nop
nop
nop
nop
nop
nop
nop
nop
#endasm
}
}
void SPI1_DelayTick10us(UC_8 t){
for (; t>0; t--){
Spi1_Delay10us();
}
}
/*
********************************************************************************
* Function name : Spi1_SendChar() *
********************************************************************************
* Author : Alessandro Cervellin *
* Input parameters : date to send *
* Return value : none *
* Function description : asend a single data byte *
* Notes : *
* *
* --- Function History ------------------------------------------------------- *
* *
* -------------------------------------------------------------------------- *
* | Date | Notes | *
* |----------|---------------------------------------------------------------| *
* |S 16/02/10| Base Relesase | *
* |E 16/02/10| | *
* |----------|---------------------------------------------------------------| *
* | | | *
* -------------------------------------------------------------------------- *
* *
* --- Open issues ------------------------------------------------------------ *
* *
********************************************************************************
*/
void Spi1_SendChar (UC_8 data){
while (!SPI1S_SPTEF); /* wait until transmit buffer is empty*/
SPI1D = data; /* Transmit counter*/
}
/*
********************************************************************************
* Function name : Spi1_SlaveSelect() *
********************************************************************************
* Author : Alessandro Cervellin