MSP430_SPI_Master_Read_Write

Publisher:Lihua1314520Latest update time:2017-11-25 Source: eefocusKeywords:MSP430  SPI  Master  Read  Write Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/******************************************************************
**                                                       
**  File : SPI.c     | Master Send Receive Interrupt |                                    
**  Version : 1.0     
** Description: SPI interface TLC549                                                                       
**  Author : LightWu                              
**  Date : 2013-4-16                                                       
**                                                   
*******************************************************************/


#include "MSP430x24x.h"


#define uint unsigned int
#define uchar unsigned char


/***设置数码管显示****/


#define L1_OFF   P4OUT|=BIT0 //关L1
#define L1_NO    P4OUT&=~BIT0 //点亮L1
#define L2_OFF   P4OUT|=BIT1 //关L2
#define L2_NO    P4OUT&=~BIT1 //点亮L2
#define L3_OFF   P4OUT|=BIT2 //关L3
#define L3_NO    P4OUT&=~BIT2 //点亮L3




uchar const Segment1[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; //不带小数点编码
uchar const Segment2[]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10}; //带小数点编码


uchar AdcFlag = 0;


uchar TempNum1;
uchar TempNum2;
uchar TempNum3;


unsigned char Data1;


void Display( uchar num1, uchar num2, uchar num3 );


void Delay(void)
{
  uint m;
  for(m=1000;m>0;m--);
}


void SpiInit(void)
{
    P3SEL |= 0x0E;                            // P3.3,2,1 USCI_B0 option select,注意管脚配置
    P3DIR |= 0x01;                            // P3.0 output direction
    UCB0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC;       // 3-pin, 8-bit SPI mstr, MSB 1st
    UCB0CTL1 |= UCSSEL_2;                     // SMCLK
    UCB0BR0 = 0x02;
    UCB0BR1 = 0;
    UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    
    IE2 |= UCB0RXIE;            // 打开接收中断
}


unsigned char TLC549Read(void)
{
    unsigned char Data;
    
    P3OUT &= ~0x01;                         // Enable TLC549, /CS reset
    
    UCB0TXBUF = 0x55;                       // Dummy write to start SPI
    while (!(IFG2 & UCB0TXIFG));            // 发送完成
     
     
    while (!(IFG2 & UCB0RXIFG));            // USCI_B0 RX buffer ready?


    Data = UCB0RXBUF;                       // data = 00|DATA


    P3OUT |= 0x01;                          // Disable TLC549, /CS set


    return(Data);
}






void main(void)
{
        // Stop watchdog timer to prevent time out reset
        WDTCTL = WDTPW + WDTHOLD; //Turn off the watchdog
  
        P4DIR = 0XFF; //P4 is set as output, bit code control
        P4SEL = 0;
        
        P5DIR = 0XFF; //P5 is set as output, break code control
        P5SEL = 0;
        
        P4OUT = 0XFF; //Turn off the digital tube, common anode digital tube
        
        SpiInit();
        
     
        while(1)
        {
                //Data1 = TLC549Read();
            
                
                P3OUT &= ~0x01; // Enable TLC549, /CS reset
            
                UCB0TXBUF = 0x55; // Transmit first character


                _BIS_SR(LPM0_bits + GIE); // CPU off, enable interrupts
            
            
                TempNum1 = Data1/100; //Hundreds digit
                TempNum2 = Data1/10%10; //Tens digit
                TempNum3 = Data1%10; //Unit
               
                Display(TempNum1,TempNum2,TempNum3); //Display conversion value
        }
        


}




#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR (void)
{
        Data1 = UCB0RXBUF; // data = 00|DATA
        
        P3OUT |= 0x01; // Disable TLC549, /CS set
        
        __bic_SR_register_on_exit(LP M0_bits); // Exit LPM0
}   




void Display( uchar num1, uchar num2, uchar num3 )
{
    P5OUT = Segment1[ num1 ]; //
    L1_NO;
    Delay();
    L1_OFF;
    
    P5OUT = Segment1[ num2 ]; //
    L2_NO;
    Delay();
    L2_OFF;
    
    P5OUT = Segment1[ num3 ]; //
    L3_NO;
    Delay ();
    L3_OFF;
}

Keywords:MSP430  SPI  Master  Read  Write Reference address:MSP430_SPI_Master_Read_Write

Previous article:MSP430F249—SPI Master-Slave Communication
Next article:MSP430F249SPI+TLC549

Recommended ReadingLatest update time:2024-11-17 00:20

13.STC15W408AS MCU SPI
The STC15 series microcontrollers also provide another high-speed serial communication interface - SPI interface. SPI is a full-duplex, high-speed, synchronous communication bus with two operating modes: master mode and slave mode. In master mode, it supports a rate of up to 3 Mbps (when the operating frequency is 12M
[Microcontroller]
13.STC15W408AS MCU SPI
STM32F103RE uses SPI3 as slave mode
Most of the STM32 SPI routines found on the Internet are used as master mode, and there are slave mode routines in the official routines.  However, I set SPI3 to slave mode according to the official routines, and found that the MISO pin had no data output, but the timing of the host was fine.  The problem lies in the
[Microcontroller]
MSP430F5438 study notes TA1 overflow interrupt plus compare match interrupt
// Clock defaults   // FLL clock FLL select XT1   // Auxiliary clock ACLK selects XT1 32768Hz   // Main system clock MCLK selects DCOCLKDIV 8000000Hz   // Subsystem clock SMCLK selects DCOCLKDIV 8000000Hz   //TA1 selects ACLK, the maximum count value is 65535   //Compare the match value to 32768   // CCR0 interrupt P4
[Microcontroller]
Design of SPI Driver Based on Windows CE
Introduction Windows CE is an embedded operating system that supports multi-threading, multi-tasking, and preemptive. With the release of Windows CE 6.0, its kernel performance has been significantly improved and its source code is open, which will promote its wide application in consumer electronics, industri
[Microcontroller]
Design of SPI Driver Based on Windows CE
STM32-cubeMX+HAL library SPI interface usage
Summary:  This article mainly introduces the SPI interface of STM32, cubeMX software configuration of SPI interface and analysis of SPI related codes. Introduction to STM32 SPI: (1) SPI protocol    Serial Peripheral Interface is a high-speed full-duplex communication bus, mainly used for communication between MCU a
[Microcontroller]
STM32-cubeMX+HAL library SPI interface usage
Some understanding of the SSEL pin of LPC24xx's SPI
SSEL is a slave select pin, which is active at low level and is used to indicate the slave selected to participate in data transmission. Each slave has its own specific slave select input signal. SSEL must be low before data processing and remain low during the entire processing process. If the SSEL signal goes high d
[Microcontroller]
MSP430F2131 reads and writes DS1991
0|-->LED // // A. Dannenberg // Texas Instruments , Inc // January 2006 // Built with IAR Embedded Workbench Version : 3.40A //*************************************************************************** #include "msp430x20x1.h" #define TM_OUT(level) P2OUT = ((unsigned int)level) ? (P2IN|BIT4) : (P
[Microcontroller]
Design of reversing radar based on TI MSP430
  With the increasing requirements for the intelligence of automobile assisted driving systems and the networking development of automobile electronic systems, new reversing radars should be able to continuously measure and display the distance to obstacles, and have communication functions to send data to the vehicle
[Microcontroller]
Design of reversing radar based on TI MSP430
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号