Development Environment
1. Hardware platform: FS2410
2. Host: Ubuntu 12.04
ADC Register Configuration
1. Initialize ADC (ADCCON)
Set the prescaler, prescaler factor, select the A/D conversion channel, select normal mode and start the conversion
2. Determine whether the conversion is completed (ADCCON[5])
3. Read conversion results (ADCDATn)
Initialization of the serial port
See "Serial Port Communication FS2410": http://infohacker.blog.51cto.com/6751239/1223137
source code
//adc.c
#include "2410addr.h" //header file, including register settings
void putc(char ch) //send character
{
while(!(rUTRSTAT0 & 0X2)); //Judge whether the send buffer is empty
rUTXH0 = ch; //send
}
char getc(void) //Receive character
{
while(!(rUTRSTAT0 & 0X1)); //Judge whether the receiving buffer is empty
return rURXH0; //receive
}
void putstr(char *str) //Send string
{
while(*str != '')
{
if(*str == 'n')
{
putc('n');
putc('r');
}
else
putc(*str);
str++;
}
}
void wait(long long max) //delay function
{
for(; max > 0; max--)
;
}
void itoa(unsigned long value) // character conversion
{
unsigned long temp;
int i, flag = 0;
char data[4];
for(i = 0; i < 4; i++) // Clear the array
data[i] = '';
for(i = 0; i < 3; i++)
{
temp = (value >> 4 * i) & 0xf;
if(temp < 10)
data[2 - i] = '0' + temp;
else
{
if(temp <= 0xf)
data[2 - i] = 'a' + temp - 10;
}
}
putstr(" Value of AIN0 is 0x");
putstr(data);
putstr("r");
putstr("n");
}
int main(void)
{
rGPHCON = rGPHCON & ~(0xf << 4) | (0xa << 4); //Configure RDX0 and TDX0
rGPHUP = 0X0c; //Set the pull-up resistor
rUFCON0 = 0; //不用FIFO
rUMCON0 = 0; //No flow control required
rULCON0 = 0X3; //8-bit data, 1 stop bit, no parity, normal mode
rUCON0 = 0X5; //Clock source bit PCLK, interrupt mode is query
rUBRDIV0 = ((int)(50000000 / 115200 / 16) - 1); //Set the baud rate to 115200
rADCCON = 0x4c41; //Initialize ADC
putstr("nThis is ADC test:n");
unsigned long temp = 0;
while(1)
{
while((rADCCON & (1 << 15)) == 0); //Judge whether the conversion is completed
temp = rADCDAT0; //Read conversion value
temperature(temp);
rADCCON = 0x4c41; //Restart ADC
wait(200000);
}
return 0;
}
//start.S
.text
.global _start
_start:
#define WATCHDOG 0x53000000
ldr r0, =WATCHDOG
mov r1, #0
str r1, [r0]
ldr sp, =1024*4
bl main
loop:
b loop
//Makefile
adc.bin: start.S adc.c
arm-linux-gcc -c start.S -o start.o
arm-linux-gcc -c adc.c -o adc.o
arm-linux-ld -Ttext 0x30008000 start.o adc.o -o adc
arm-linux-objcopy -O binary -S adc adc.bin
clean:
rm -f *.o adc.bin
Compile and link
OK, success!
Previous article:【ARM】gpio·gpio of arm architecture
Next article:【ARM】Serial communication·FS2410·Bare metal UART
- Popular Resources
- Popular amplifiers
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
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- "Playing with the board" + lighting up the SPI touch screen of Xintao
- &FF0000 and &880000 are both red. What is the difference between these two reds?
- Internet radio design based on RSIC-V RVB2601 (3)
- LIS2MDL three-axis magnetometer package and code
- Live broadcast with prizes: Enter the TI robot production class, starting on Friday, reservations are in progress! (Share 100% to get gifts)
- Do you have any use for STM8S005C6T6? Special price for delivery
- Explanation on DSP devices and general-purpose processors (GPP)
- Impedance matching of power amplifiers
- About electromagnetic shielding
- About Phase Modulation