/******************************************************************************/
/* */
/* Technical Innovations N Solution (TINS) Design Unit */
/* */
/******************************************************************************/
/* */
/* All Rights Reserved Copyright (C) 2010, Technical Innovations N Solutions. */
/* */
/* Redistribution and use in source and binary forms, with or without */
/* modification, are not permitted in any case */
/* */
/* TINS's name may not be used to endorse or promote products derived from */
/* this software without specific prior written permission. */
/* */
/******************************************************************************/
/******************************************************************************/
/* All Rights Reserved Copyright (C) 2010, Technical Innovations N Solutions. */
/* */
/* \File Name : SPI.c */
/* \Author : Saikanth.M */
/* \Version : IRDA_UART */
/* \Date : 30/12/2010 */
/* */
/* SPI_Driver Software Framework */
/******************************************************************************/
/******************************************************************************/
/* System Header files */
/******************************************************************************/
#include <msp430x47x3.h>
/******************************************************************************/
/* User Header Files Section */
/******************************************************************************/
#include "Includes.h"
#include "SPI.h"
#include "SPI_Priv.h"
/******************************************************************************/
/* Global Definitions Section */
/******************************************************************************/
/******************************************************************************/
/* Global Variables Section */
/******************************************************************************/
INT8U u8_gRecUSCIA0;
INT8U u8_gRecUSCIB0;
INT8U u8_gRecUSCIA1;
INT8U u8_gRecUSCIB1;
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR (void)
{
u8_gRecUSCIA0 = UCA0RXBUF;
}
__interrupt void USCIB0RX_ISR (void)
{
u8_gRecUSCIB0= UCB0RXBUF;
}
#pragma vector=USCIAB1RX_VECTOR
__interrupt void USCIA1RX_ISR (void)
{
u8_gRecUSCIA1 = UCA1RXBUF;
}
__interrupt void USCIB1RX_ISR (void)
{
u8_gRecUSCIB1 = UCB1RXBUF;
}
/******************************************************************************/
/* Function Name: void SPI_Init(SPIConfigParams_t *f_pSPIParams) */
/* */
/* Description : Initialize the Function of SPI */
/* */
/* Parameter : *f_pSPIParams - Function input parameter */
/* */
/* Return Value : void */
/* */
/* Remarks : None */
/******************************************************************************/
void USCI_SPIInit(INT8U u8_fDevSel, SPI_CONFIG_PARAMS *f_SPIParams)
{
switch(u8_fDevSel)
{
case SPI_USCIA0:
{
/* Software Reset */
UCA0CTL1 |= UCSWRST;
/* Select the Synchronous Mode for SPI Selection */
UCA0CTL0 |= SPI_SYNCH_MASK;
/* Select the SMCLK */
UCA0CTL1 |= UCSSEL_2 + UCSWRST;
/* Select the SPI polarity and Phase */
switch(f_SPIParams->SPI_PhasePolarity)
{
case SPI_MODE0:
{
/* Select the SPI Mode0 Phase:0 and Polarity:0 */
UCA0CTL0 |= SPI_MODE0_MASK;
}
break;
case SPI_MODE1:
{
/* Select the SPI Mode1 Phase:0 and Polarity:1 */
UCA0CTL0 |= SPI_MODE1_MASK;
}
break;
case SPI_MODE2:
{
/* Select the SPI Mode2 Phase:1 and Polarity:0 */
UCA0CTL0 |= SPI_MODE2_MASK;
}
break;
case SPI_MODE3:
{
/* Select the SPI Mode3 Phase:1 and Polarity:1 */
UCA0CTL0 |= SPI_MODE3_MASK;
}
break;
default:
break;
}
/* Select the MSB Bit First */
UCA0CTL0 |= UCMSB;
switch(f_SPIParams->SPI_MasterSlaveMode)
{
case SPI_MASTER_MODE:
{
/* Select the Master Mode */
UCA0CTL0 |= UCMST;
}
break;
case SPI_SLAVE_MODE:
{
/* Select the Slave Mode */
UCA0CTL0 &= ~UCMST;
}
break;
default:
break;
}
switch(f_SPIParams->SPI_USCIModeSel)
{
case SPI_3PIN_MODE:
{
/* select the SPI 3pin Mode */
UCA0CTL0 |= UCMODE_0;
}
break;
case SPI_4PIN_UCSTE_ACTIVE:
{
/* Select the SPI 4 Pin with STE Pin Active */
UCA0CTL0 |= UCMODE_1;
}
break;
case SPI_4PIN_UCSTE_INACTIVE:
{
/* Select the 4Pin with STE Pin Low */
UCA0CTL0 |= UCMODE_2;
}
break;
default:
break;
}
/* Put the Lower Value in BR0 */
UCA0BR0 = ((SPI_CLOCK_FREQ/f_SPIParams->SPIBaudRate) & (0x00FF));
/* Select the Upper Bit Value in BR1 */
UCA0BR1 = (((SPI_CLOCK_FREQ/f_SPIParams->SPIBaudRate) & (0xFF00)) >> 8);
/* Clear the Software Reset */
UCA0CTL1 &= ~UCSWRST;
/* Enable the Interrupts */
IE2 |= UCA0RXIE;
_BIS_SR(GIE);
}
break;
case SPI_USCIA1:
{
/* Software Reset */
UCA1CTL1 |= UCSWRST;
/* Select the Synchronous Mode for SPI Selection */
UCA1CTL0 |= SPI_SYNCH_MASK;
/* Select the SMCLK */
UCA1CTL1 |= UCSSEL_2 + UCSWRST;
/* Select the SPI polarity and Phase */
switch(f_SPIParams->SPI_PhasePolarity)
{
case SPI_MODE0:
{
/* Select the SPI Mode0 Phase:0 and Polarity:0 */
UCA1CTL0 |= SPI_MODE0_MASK;
}
break;
case SPI_MODE1:
{
/* Select the SPI Mode1 Phase:0 and Polarity:1 */
UCA1CTL0 |= SPI_MODE1_MASK;
}
break;
case SPI_MODE2:
{
/* Select the SPI Mode2 Phase:1 and Polarity:0 */
UCA1CTL0 |= SPI_MODE2_MASK;
}
break;
case SPI_MODE3:
{
/* Select the SPI Mode3 Phase:1 and Polarity:1 */
UCA1CTL0 |= SPI_MODE3_MASK;
}
break;
default:
break;
}
/* Select the MSB Bit First */
UCA1CTL0 |= UCMSB;
switch(f_SPIParams->SPI_MasterSlaveMode)
{
case SPI_MASTER_MODE:
{
/* Select the Master Mode */
UCA1CTL0 |= UCMST;
}
break;
case SPI_SLAVE_MODE:
{
/* Select the Slave Mode */
UCA1CTL0 &= ~UCMST;
}
break;
default:
break;
}
switch(f_SPIParams->SPI_USCIModeSel)
{
case SPI_3PIN_MODE:
{
/* select the SPI 3pin Mode */
UCA1CTL0 |= UCMODE_0;
}
break;
case SPI_4PI
SPI.zip_WORKING
版权申诉
186 浏览量
2022-09-22
21:20:02
上传
评论
收藏 4KB ZIP 举报
JaniceLu
- 粉丝: 79
- 资源: 1万+
最新资源
- 6_Advertising-gd_LearningRate.ipynb
- 12_base.apk
- 520马上到了两款动态爱心表白HTML代码(附源码)李峋同款爱心,快送给你爱的她或(他)吧12 情侣纪念日代码.zip
- 电子设计竞赛的单相不间断电源设计
- cutcamera1715961370938.png
- 基于MATLAB的图像处理课程设计报告.doc
- tensorflow-gpu-2.6.0-cp38-cp38-manylinux2010-x86-64.whl
- mmexport1715960553858.png
- tensorflow-gpu-2.6.0-cp37-cp37m-manylinux2010-x86-64.whl
- 通过 .NET 应用程序中的源代码查找 SQL 注入
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈