当前位置:网站首页>Lesson 4 serial port and clock

Lesson 4 serial port and clock

2022-06-26 05:26:00 Super cute sandwich kids

1.CC2530 During normal operation, a high-frequency clock signal and a low-frequency clock signal are required
  High frequency clock signals are mainly supplied to CPU Make sure the program runs ; The low-frequency clock signal is mainly supplied to the watchdog 、 Sleep timer and other on-chip peripherals .
2. The source of the clock signal
  High frequency clock signal has 2 individual , Internal to the chip 16M RC ; disjunctive 32M Quartz crystal oscillator (2 Choose one of them to supply CPU)
  Low frequency clock signal has 2 individual , Internal to the chip 32K RC ; disjunctive 32.768K Quartz crystal oscillator (2 Choose one of them for the watchdog 、 Sleep timer and other on-chip peripherals )
3.CC2530 When the chip is powered on by default , It's internal 2 individual RC The circuit is used as the clock source of high frequency and low frequency .
4. If we're using a serial port , Especially when wireless communication , It must be used. 32M Quartz crystal oscillator as the source of high-frequency clock .
5. Characteristics of high frequency clock :2 A high-frequency clock source can vibrate at the same time to generate a high-frequency clock signal ; and 2 Only one low-frequency clock source can vibrate at a time , And the starting clock source supplies CC2530.

System high frequency clock switching steps :( from 16M RC Switch to 32M )
1. Give Way 2 A high-frequency clock source vibrates
2. Wait for the target clock source to vibrate and stabilize
3. Delay for a short time 63us
4. No frequency division output Regardless of the frequency 32M, Dichotomy 16M,
5. Select the target high frequency clock source as the system master clock source
6. Confirm whether the current working system clock is the selected high-frequency clock
SLEEPCMD 、SLEEPSTA 、CLKCONCMD 、CLKCONSTA ,CMD: Write register ,STA: Status register

1. Give Way SLEEPCMD The first 2 Position as 0
2. Give Way SLEEPSTA The first of the registers 6 Position as 1, Express 32M The clock source is stable
3. exceed 63us Time delay
4. Put the register CLKCONCMD It's low 3 Bit is set to 000, Indicates no frequency division output
5. Put the register CLKCONCMD Of the 6 Positional clarity 0, Set to 32M As the system master clock ( If you put 1 It is 16M)
6 If you read CLKCONSTA The number of this register is 6 Position as 0, Express 32M The clock source of has been used as the master clock of the system , The system can continue to run .( Inspection function )

Example 1: Let the nixie tube show 0-9,16M Output
#include<iocc2530>
#include"74LS164_8LED.h"
void delay()
{
  int i,j;
  for(i=0;i<1000;i++)
    for(j=0;j<800;j++)
}
void main()
{
 char i;
  LS164_Cfg();// initialization
  while(1)
  {
    for(i=0;i<10;i++)
     {
          LS164_BYTE(i);// The nixie tube displays from 0 To 9
            delay();// The time delay function
     }
  }
}

Example 2: Let the nixie tube show 0-9,32M Output
#include<iocc2530>
#include"74LS164_8LED.h"
void delayus()
{
  char k=63;
   while(k--);
}
void delay()
{
  int i,j;
  for(i=0;i<1000;i++)
    for(j=0;j<800;j++)
}
void Init32M()
{
  SEELPCMD &=0xFB; //1111 1011 Turn on 2 A high frequency clock source
  while(SLEEPSTA &0x40);// 0100 0000 wait for 32M Stable
  delayus();// Time delay 63u function
  CLKCONCMD &=0xF8;//1111 1000 No frequency division output
  CLKCONCMD &=0xBF;//1011 1111 Set up 32M Master clock
  while(CLKCONSTA &0x40);//0100 0000 wait for 32M Successfully become the master clock of the current system
}
void main()
{
 char i;
  LS164_Cfg();// initialization
  while(1)
  {
    for(i=0;i<10;i++)
     {
          LS164_BYTE(i);// The nixie tube displays from 0 To 9
            delay();// The time delay function
     }
  }
}

Master the switching of the clock 、 Control serial port
CC2530 have 2 A serial port , And each serial port can be configured with a selection control pin
Configuration of serial port position :
1. Specify the serial port IO Location ; Alternate position 1 Alternate position 2
2. The corresponding IO Configure on-chip peripheral functions ;
3.8 Data bits 、1 Stop bits 、 No flow control 、 No verification established .
4. Baud rate ;
5. open CPU interrupt 、 Corresponding serial port receiving interrupt ;

#include<iocc2530.h>
void Init32M()
{
  SEELPCMD &=0xFB; //1111 1011 Turn on 2 A high frequency clock source
  while(SLEEPSTA &0x40);// 0100 0000 wait for 32M Stable
  delayus();// Time delay 63u function
  CLKCONCMD &=0xF8;//1111 1000 No frequency division output
  CLKCONCMD &=0xBF;//1011 1111 Set up 32M Master clock
  while(CLKCONSTA &0x40);//0100 0000 wait for 32M Successfully become the master clock of the current system
}
void UartCfg()
{// A serial port 0 Your spare location 1 Configure baud rate 9600
   PERCFG &=0xF1;//1111 0001 Select serial port 0 Your spare location 1;
   P0SEL |=0x0C;//0000 1100 P0_2 P0_3 For on-chip peripheral functions
   U0CSR |=0xC0;//
   U0GCR =8;
   U0BAUD =59;
    EA=1; // Open total interrupt
    URX0IE=1;
}
void main()
{
   Init32M();
   UartCfg();
   while(1);
}

#pragma vector=URX0_VECTOR
__interrupt void URX0_IR0(void)
{
     char ch;
     URX0IF=0;// Serial port data bit flag , The hardware will be set 1, Software clearance 0
     ch=U0DBUF;// Take bytes from the receiving register and store them in ch

     U0DBUF=ch;// Put variables ch The value in is assigned to the sending serial port 0 Send register
     while(UTX0IF==0);
     UTX0IF=0;
   
}

原网站

版权声明
本文为[Super cute sandwich kids]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180507092295.html