The microcontroller source program is as follows:
/****************************************************************
File name: Main.c
Function description: Main program
********************************************************************/
#define GLOBAL_CLK 1
#include #include #include "def.h" #include "option.h" #include "2440addr.h" #include "2440lib.h" #include "2440slib.h" #include "Uart.h" void SPI_Init(void); void WriteByte_MMA7455L(U8 addr,U8 dat); U8 ReadByte_MMA7455L(U8 addr); static U32 cpu_freq; static U32 UPLL; static void cal_cpu_bus_clk(void) { U32 val; U8 m, p, s; val = rMPLLCON; //MPLLCON power-on initial value is 0x00096030 m = (val>>12)&0xff; //The result is 0x96=150 p = (val>>4)&0x3f; //The result is 0x03=3 s = val&3; //The result is 0 //(m+8)*FIN*2 Do not exceed 32 digits! FCLK = ((m+8)*(FIN/100)*2)/((p+2)*(1< m = (val>>1)&3; p = val&1; val = rCAMDIVN; s = val>>8; switch (m) { case 0: HCLK = FCLK; break; case 1: HCLK = FCLK>>1; break; case 2: if(s&2) HCLK = FCLK>>3; else HCLK = FCLK>>2; break; case 3: if(s&1) HCLK = FCLK/6; else HCLK = FCLK/3; break; } if(p) PCLK = HCLK>>1; else PCLK = HCLK; if(s&0x10) cpu_freq = HCLK; else cpu_freq = FCLK; val = rUPLLCON; m = (val>>12)&0xff; p = (val>>4)&0x3f; s = val&3; UPLL = ((m+8)*FIN)/((p+2)*(1< } void Main(void) { U8 key,sta; int i; U32 mpll_val = 0; i = 2 ; switch ( i ) { case 0: //200 key = 12; mpll_val = (92<<12)|(4<<4)|(1); break; case 1: //300 key = 13; mpll_val = (67<<12)|(1<<4)|(1); break; case 2: //400M key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; case 3: //440!!! key = 14; mpll_val = (102<<12)|(1<<4)|(1); break; default: key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; } //rMPLLCON is assigned 0x5c011 ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3); ChangeClockDivider(key, 12); //key=14 cal_cpu_bus_clk(); Port_Init(); //IO port initialization SPI_Init(); //SPI initialization MMA7455L_INIT(); //MMA7455L initialization Uart_Init(); //Serial port initialization Uart_Select(0); Delay(5); //Delay 10ms to let IIC and SPI get ready Uart_Printf("CLKCON=%x!",rCLKCON); Uart_Printf("Start sending data!nn"); //Write configuration data 0x05 to the 0x16 register of MMA7455L WriteByte_MMA7455L(0x16,0x05); //Read back the configuration value of register 0x16 to determine whether the SPI communication is successful. sta = ReadByte_MMA7455L (0x16); Uart_Printf("sta=0x%x",sta); while(1) { } } void WriteByte_MMA7455L(U8 addr,U8 dat) { int n; //Set chip select CS to low to enable MMA7455 in SPI mode rGPFDAT &= 0xef; Delay(1); Uart_Printf("The data of SPI status register is 0x%x!n",rSPSTA0); while(!(rSPSTA0&0x01==0x01)) ; //High position 1 write operation rSPTDAT0 = 0x80|((addr & 0x3f)<<1); Uart_Printf("The data of SPI status register is 0x%x!n",rSPSTA0); Uart_Printf("Write operation address sent successfully!n"); for(n=0;n<20;n++); Uart_Printf("The data of SPI status register is 0x%x!n",rSPSTA0); while(!(rSPSTA0&0x01==0x01)) ; rSPTDAT0 = dat; //write data Uart_Printf("The data of SPI status register is 0x%x!n",rSPSTA0); Uart_Printf("Write operation data sent successfully!n"); for(n=0;n<20;n++); // Set chip select CS to high level to end SPI communication rGPFDAT |= 0xff; Delay(1); } U8 ReadByte_MMA7455L(U8 addr) { int n; U8 Re_Dat; //Set chip select CS to low level to enable MMA7455L in SPI mode rGPFDAT &= 0xef; Delay(1); Uart_Printf("The data of SPI status register is 0x%x!n",rSPSTA0); while(!(rSPSTA0&0x01==0x01)) ; //Read operation high clear 0 rSPTDAT0 = (addr & 0x3f)<<1; Uart_Printf("The data of SPI status register is 0x%x!n",rSPSTA0); Uart_Printf("Read operation address sent successfully!n"); for(n=0;n<20;n++); Uart_Printf("The data of SPI status register is 0x%x!n",rSPSTA0); while(!(rSPSTA0&0x01==0x01)); Re_Dat = rSPRDAT0; Uart_Printf("The data of SPI status register is 0x%x!n",rSPSTA0); for(n=0;n<20;n++); // Set chip select CS to high level to end SPI communication rGPFDAT |= 0xff; Delay(1); //Return read data return Re_Dat; } //MMA7455L initialization void MMA7455L_INIT(void ) { MMA_QUEUE.MMA_HEAD=0; MMA_QUEUE.MMA_CUR=0; SPI_WriteREG(0x16,0x05); //Level mode delay_nus(10); SPI_WriteREG(0x18,0x20); delay_nus(10); SPI_WriteREG(0x19,0x00); delay_nus(10); SPI_WriteREG(0x1a,0x00); delay_nus(10); } //SPI initialization void SPI_Init(void) { //Activate the SPI bit of the clock controller rCLKCON |= 1 << 18; rSPCON0 = (0<<6)|(0<<5)|(1<<4)|(1<<3)|(0<<2)|(0<<1)|1; //Query mode; SCK enable; host mode; clock low level is valid; format A; normal mode; //The SPI transmission baud rate of MMA7455 can reach up to 4MHz when the operating voltage is less than 2.4V, and up to 8MHz when it is greater than 2.4V //SPI baud rate is 50MHz/2/(24+1)=1MHz rSPPRE0 = 24; } val = rCLKDIVN; UCLK = (rCLKDIVN&8)?(UPLL>>1):UPLL;
Previous article:Proteus simulation ARM7 LPC2101 AD converter source program
Next article:S3C2440 microcontroller external interrupt experiment
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- EEWORLD University Hall ---- Teacher Tang explains the real questions of the electronic competition
- Motor control circuit, MOS burnt out
- I would like to ask a question about the discrete device BUCK circuit
- The idle "four-piece set", have the contemporary young people collected them all?
- There was an earthquake. There have been too many earthquakes in the past two days.
- National Technology Virtual Serial Port/CDC and Development Board Onboard NS_LINK Driver
- Design of filter module based on combination of single chip microcomputer and FPGA
- TMS320C6000 Series DSP Programming Tools and Guides
- GigaDevice GD32450I-EVAL Review Summary
- EEWORLD University - Hejian Software Classroom - Why is FPGA prototype verification becoming more and more important?