2nd note of SCM based on CCS and MSP430f5529

2nd note of communication: UART

  Now I’ve made my own decision, I will pay whatever to learn CCS and TI hardware include DSPs and SCM, I found that my major would be nothing without the hardware.
  So let’s begin now, the communication start from UART. what is UART exactly? it’s a very common signal communication, which is asynchronous(异步), that’s mean it won’t send data timely when it receive some signal, so the physical clock line is not required. Two devices communicate with each other will need three pins called ‘rxd’ , ‘txd’ and ‘ground’. they will have a base rate to exchange data: the baud rate. it will decide how many words can be sent per minute.
‘from baidu’
  How does it work on the board? well, like this:
在这里插入图片描述
  Some essential rule is made here, such as the edge-detection has been set in advance(I was confused about that since some knowledge about FPGA. and I did’t this message, which made me confused about the sample code.
  Based on the MSP430 series board, the most important part is reading user guide&set many register of the chip(copy code actually). Even you have had a good command of C, while you try to design the code of 430 you will found you know nothing about C(bushi). the core knowledge is about underlying logic.so these data .pdf is so essential include user guide, datasheet, schematic diagram.
  The automatic baud-rate detection mode can be used in a full-duplex communication system with somere strictions. The USCI can not transmit data while receiving the break/sync field and, if a 0h byte with framing error is received, any data transmitted during this time gets corrupted. The latter case can be discovered by checking the received data and the UCFE bit.
  The message from user guide indicates that most of detection work is set previously in the devices, we don’t need to configure the edge detection or the begin flag. That’a a very typical work model of 430, since they will arrange every switch(actually register), and if you know the principal like UART, you just need to learn how to set relative register(UCxCTLx, UCxBRx). In my own view, I think it seems like RTL level of FPGA.
  Let’s back to UART itself, based on it’s protocol and characteristic, we know that, the Baud rate is a essential part, and it won’t work in the main procedure of the program(unless you are testing the UART module of a device), we need to preset both devices baud rate to make sure they can communicate correctly. But the most important part is the interrupt . whether it’s UART or SPI or IIC, it’s a communication, and we can’t predict what time will we receive the data, so in the hardware protocol, usually some data flag is required to detect communication module is working. that’s actually how the interrupt module work. if we preset some UART&communication register, then it will work like this:
receive data mark->mechanism check if it’s valid->(if it’s true)->interrupt flag=1->program execute the interrupt function-> data into the RXTBUFFER
  if some error happen or the mark is invalid, the interrupt flag will not be set as 1(interrupt was not triggered).
  let’s try to give some example and comment it(TI and CCS have brought own example code for you to learn, it’s easy to get their example):
tape here to learn how to import code:https://blog.csdn.net/redgragon0/article/details/79197271

//                 MSP430F552x
//             -----------------
//         /|\|                 |
//          | |                 |
//          --|RST              |
//            |                 |
//            |     P3.3/UCA0TXD|------------>
//            |                 | 115200 - 8N1
//            |     P3.4/UCA0RXD|<------------
// that's very iconic hhhhh

#include <msp430.h>
/*
the main fuction will keep work in a loop, and if a interrupt haprrened
the main function will stop and some register will save the process of main 
function then go to execute interrupt function,and normally some register 
will be preset in main fuction, most of them like a switch, and actually like 
the clock, they have default clock of the three signal clock, but if you need 
some other frequncy of physical clock, you need to know how to set these switch
*/
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  P3SEL |= BIT3+BIT4;                       // P3.3,4 = USCI_A0 TXD/RXD
  UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
  UCA0BR0 = 9;                              // 1MHz 115200 (see User's Guide)
  UCA0BR1 = 0;                              // 1MHz 115200
  UCA0MCTL |= UCBRS_1 + UCBRF_0;            // Modulation UCBRSx=1, UCBRFx=0
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
  __no_operation();                         // For debugger,this sentence will do 
 // nothing but will be helpful if you want to make it stop here if you need to debug 
  
}

// Echo back RXed character, confirm TX buffer is ready first
/*
here is the interupt function, we can deploy the UCAxIFg(flag) and TX/RX buffer
then we can decide where will the data go after we receive data or sent the data 
into TXbuffer.
*/
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
  switch(__even_in_range(UCA0IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
    while (!(UCA0IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
    UCA0TXBUF = UCA0RXBUF;                  /* TX -> RXed character, the data got from RXbuffer will immediately transport to TXbuffer, which mean once the device 
got the data, it will send the data back timely*/
    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;
  }
}

  I think that UART or interrupt is not so hard while it will cost a lot of time to learn how to set these complex registers. let’s keep overcome it!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值