lpc_adc_dma#
Overview#
The lpc_adc_dma example shows how to use LPC ADC driver with DMA.
In this example, the sensor is used to created the input analog signal. When user type in any key from the keyboard, the software trigger API is called to start the conversion. When the ADC conversion is completed, it would trigger the DMA to move the ADC conversion result from ADC conversion data register to user indicated memory. Then the main loop waits for the transfer to be done and print the result to terminal.
Project Information#
1.what are ADC conversion sequences? A conversion sequence is a single pass through a series of A/D conversions performed on a selected set of A/D channels. Software can set-up two independent conversion sequences, either of which can be triggered by software or by a transition on one of the hardware triggers. Each sequence can be triggered by a different hardware trigger. One of these conversion sequences is referred to as the A sequence and the other as the B sequence. It is not necessary to employ both sequences. An optional single-step mode allows advancing through the channels of a sequence one at a time on each successive occurrence of a trigger. The user can select whether a trigger on the B sequence can interrupt an already-in-progress A sequence. The B sequence, however, can never be interrupted by an A trigger.
How to use software-triggered conversion? There are two ways that software can trigger a conversion sequence:
Start Bit: The first way to software-trigger an sequence is by setting the START bit in the corresponding SEQn_CTRL register. The response to this is identical to occurrence of a hardware trigger on that sequence. Specifically, one cycle of conversions through that conversion sequence will be immediately triggered except as indicated above. (In this example, we use this way.)
Burst Mode: The other way to initiate conversions is to set the BURST bit in the SEQn_CTRL register. As long as this bit is 1 the designated conversion sequence will be continuously and repetitively cycled through. Any new software or hardware trigger on this sequence will be ignored.
How to use DMA to work with ADC? The sequence-A or sequence-B conversion/sequence-complete interrupts may also be used to generate a DMA trigger. To trigger a DMA transfer, the same conditions must be met as the conditions for generating an interrupt. Remark: If the DMA is used, the ADC interrupt must be disabled in the NVIC.
Program Flow#
1.This example demonstrates how to configure the A sequences with interrupt, assigning one channel with software trigger, you can configure channel via “DEMO_ADC_SAMPLE_CHANNEL_NUMBER”.
2.Before configuration of the ADC begins, the ADC is put through a self-calibration cycle.
3.Configure the DMA and DMAMUX to work with ADC sequences.
4.Enable the Conversion-Complete or Sequence-Complete DMA for sequences A.
5.After ADC channels are assigned to each of the sequences, if the user enters any key via terminal, software trigger will start.
6.When the conversion completes, the DMA would be requested.
7.When the DMA transfer completes, DMA will trigger a interrupt. ISR would set the “bDmaTransferDone” to ‘true’. Then main function will print conversion result to terminal.
Supported Boards#
LPC845BREAKOUT
Hardware requirements
Micro USB cable
LPC845 Breakout board
Personal Computer
Board settings
ADC CH0 input signal 32(PIO0-7).
Prepare the demo
Connect a micro USB cable between the PC host and the CMSIS DAP USB port on the board.
Open a serial terminal with the following settings:
9600 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target board.
Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.
Running the demo
Adjust the potentiometer and press any key from keyboard to trigger the conversion. The log below shows the output of the ADC dma driver example in the terminal window:
ADC DMA example.
ADC Calibration Done.
Configuration Done.
Type in any key to trigger the conversion ...
Conversion word : 0x80025F30
Conversion value: 1523
Conversion word : 0x80025F30
Conversion value: 1523
Conversion word : 0x80025F30
Conversion value: 1522
...
LPCXpresso51U68
Hardware requirements
Mini/micro USB cable
LPCXpresso51U68 board
Personal Computer
Board settings
ADC CH4 input signal J1-15(PIO1-1).
Prepare the Demo
Connect a USB cable between the host PC and the OpenSDA USB port on the target board.
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target board.
Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.
Running the demo
Press any key from keyboard and trigger the conversion. The log below shows example output of the ADC DMA example in the terminal window:
ADC DMA example.
ADC Calibration Done.
Configuration Done.
ADC Full Range: XXXX
Type in any key to trigger the conversion ...
Conversion word : 0x80022A70
Conversion value: 679
Conversion word : 0x80022930
Conversion value: 659
Conversion word : 0x800228F0
Conversion value: 655
Conversion word : 0x80022920
Conversion value: 658
Conversion word : 0x80022920
Conversion value: 658
...
LPCXpresso54628
Hardware requirements
Micro USB cable
LPCXpresso54628 board
Personal Computer
Board settings
ADC CH4 input signal J12-2(PIO0-16).
Prepare the Demo
Connect a micro USB cable between the host PC and the LPC-Link USB port (J8) on the target board.
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target board.
Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.
Running the demo
Press any key from keyboard and trigger the conversion. The log below shows example output of the ADC DMA example in the terminal window:
ADC DMA example.
ADC Calibration Done.
Configuration Done.
ADC Full Range: XXXX
Type in any key to trigger the conversion ...
Conversion word : 0x80022A70
Conversion value: 679
Conversion word : 0x80022930
Conversion value: 659
Conversion word : 0x800228F0
Conversion value: 655
Conversion word : 0x80022920
Conversion value: 658
Conversion word : 0x80022920
Conversion value: 658
...
LPCXpresso54S018
Hardware requirements
Micro USB cable
LPCXpresso54S018 board
Personal Computer
Board settings
ADC CH4 input signal J12-2(PIO0-16).
Prepare the Demo
Connect a micro USB cable between the host PC and the LPC-Link USB port (J8) on the target board.
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target board.
Launch the debugger in your IDE to begin running the demo.
Running the demo
This demo is an external flash plain load demo, ROM will copy image in external flash to SRAMX to run:
Build the demo to generate a bin file. Note: If need to generate bin file using MCUXpresso IDE, below steps need to be followed: Set in example Properties->C/C++ Build->Settings->Build steps->Post-build steps->Edit enbable arm-none-eabi-objcopy -v -O binary “&{BuildArtifactFileName}” “&{BuildArtifactFileBaseName}.bin”
This plainload example linked the vector table to 0x00000000, but program to external flash 0x10000000.
Program the bin file to external on board flash via SEGGER J-FLASH Lite(V6.22 or higher):
a. Open SEGGER J-FLASH Lite, select device LPC54S018.
b. Click the ‘Erase Chip’ to erase the extrenal flash.(if can not success, press SW4 button and reset the board, and try to erase again)
c. Select the bin data file, set the ‘.bin/Erase Start’ address to 0x10000000, then click ‘Program Device’ Note: Please use above way to program the binary file built by armgcc tool chain to external flash. For IAR, KEIL, MCUXpresso IDE, you can use the IDE tool to program the external flash.
Press any key from keyboard and trigger the conversion. The log below shows example output of the ADC DMA example in the terminal window:
ADC DMA example.
ADC Calibration Done.
Configuration Done.
ADC Full Range: XXXX
Type in any key to trigger the conversion ...
Conversion word : 0x80022A70
Conversion value: 679
Conversion word : 0x80022930
Conversion value: 659
Conversion word : 0x800228F0
Conversion value: 655
Conversion word : 0x80022920
Conversion value: 658
Conversion word : 0x80022920
Conversion value: 658
...
LPCXpresso54S018M
Hardware requirements
Micro USB cable
LPCXpresso54S018M board
Personal Computer
Board settings
ADC CH4 input signal J12-2(PIO0-16).
Prepare the Demo
Connect a micro USB cable between the host PC and the LPC-Link USB port (J8) on the target board.
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target board.
Launch the debugger in your IDE to begin running the demo.
Running the demo
This demo is an external flash plain load demo, ROM will copy image in external flash to SRAMX to run:
Build the demo to generate a bin file. Note: If need to generate bin file using MCUXpresso IDE, below steps need to be followed: Set in example Properties->C/C++ Build->Settings->Build steps->Post-build steps->Edit enbable arm-none-eabi-objcopy -v -O binary “&{BuildArtifactFileName}” “&{BuildArtifactFileBaseName}.bin”
This plainload example linked the vector table to 0x00000000, but program to external flash 0x10000000.
Program the bin file to external on board flash via SEGGER J-FLASH Lite(V6.22 or higher):
a. Open SEGGER J-FLASH Lite, select device LPC54S018M.
b. Click the ‘Erase Chip’ to erase the extrenal flash.(if can not success, press SW4 button and reset the board, and try to erase again)
c. Select the bin data file, set the ‘.bin/Erase Start’ address to 0x10000000, then click ‘Program Device’ Note: Please use above way to program the binary file built by armgcc tool chain to external flash. For IAR, KEIL, MCUXpresso IDE, you can use the IDE tool to program the external flash.
Press any key from keyboard and trigger the conversion. The log below shows example output of the ADC DMA example in the terminal window:
ADC DMA example.
ADC Calibration Done.
Configuration Done.
ADC Full Range: XXXX
Type in any key to trigger the conversion ...
Conversion word : 0x80022A70
Conversion value: 679
Conversion word : 0x80022930
Conversion value: 659
Conversion word : 0x800228F0
Conversion value: 655
Conversion word : 0x80022920
Conversion value: 658
Conversion word : 0x80022920
Conversion value: 658
...
LPCXpresso824MAX
Functional Description
1.This example demonstrates how to configure the A sequences with interrupt, assigning one channel with software trigger, you can configure channel via “DEMO_ADC_SAMPLE_CHANNEL_NUMBER”.
2.Before configuration of the ADC begins, the ADC is put through a self-calibration cycle.
3.Configure the DMA and DMAMUX to work with ADC sequences.
4.Enable the Conversion-Complete or Sequence-Complete DMA for sequences A.
5.After ADC channels are assigned to each of the sequences, if the user enters any key via terminal, software trigger will start.
6.When the conversion completes, the DMA would be requested.
7.When the DMA transfer completes, DMA will trigger a interrupt. ISR would set the “bDmaTransferDone” to ‘true’. Then main function will print conversion result to terminal.
Hardware Requirements
Micro USB cable
LPCXpresso824MAX board
Personal Computer
Board Settings
ADC CH1 input signal J5-1(PIO0-6).
Run the Project
Run this example by performing the following steps:
Connect a micro USB cable between the PC host and the CMSIS DAP port(J3 on the LPCXpresso824MAX board) for receiving debug information.
Open a serial terminal in PC(for example PUTTY) with the following settings:
9600 baud rate
8 data bits
No parity
One stop bit
No flow control
Compile and download the program to the target board. More information about how to compile and program the project can refer to
[Getting Started with MCUXpresso SDK](../../../../../docs/Getting Started with MCUXpresso SDK.pdf).
Monitor the information on the debug console.
Expected Result
Press any key and print user channel’s result in serial terminal.
LPCXpresso845MAX
Functional Description
1.This example demonstrates how to configure the A sequences with interrupt, assigning one channel with software trigger, you can configure channel via “DEMO_ADC_SAMPLE_CHANNEL_NUMBER”.
2.Before configuration of the ADC begins, the ADC is put through a self-calibration cycle.
3.Configure the DMA and DMAMUX to work with ADC sequences.
4.Enable the Conversion-Complete or Sequence-Complete DMA for sequences A.
5.After ADC channels are assigned to each of the sequences, if the user enters any key via terminal, software trigger will start.
6.When the conversion completes, the DMA would be requested.
7.When the DMA transfer completes, DMA will trigger a interrupt. ISR would set the “bDmaTransferDone” to ‘true’. Then main function will print conversion result to terminal.
Hardware Requirements
Micro USB cable
LPCXpresso845MAX board
Personal Computer
Board Settings
ADC CH0 input signal J1-6(PIO0-7).
Run the Project
Run this example by performing the following steps:
Connect a micro USB cable between the PC host and the CMSIS DAP port(J4 on the LPCXpresso845MAX board) for receiving debug information.
Open a serial terminal in PC(for example PUTTY) with the following settings:
9600 baud rate
8 data bits
No parity
One stop bit
No flow control
Compile and download the program to the target board. More information about how to compile and program the project can refer to
[Getting Started with MCUXpresso SDK](../../../../../docs/Getting Started with MCUXpresso SDK.pdf).
Monitor the information on the debug console.
Expected Result
Press any key and print user channel’s result in serial terminal.
LPCXpresso860MAX
Hardware requirements
Micro USB cable
LPCXpresso860max board
Personal Computer
Board settings
ADC CH0 input signal J6-12(PIO0-7).
Prepare the Demo
Connect a micro USB cable between the PC host and the CMSIS DAP USB port (J4) on the board
Open a serial terminal with the following settings:
9600 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target board.
Press reset button to begin running the demo.
Running the demo
Monitor the information on the debug console.
Expected Result
Press any key and print user channel’s result in serial terminal.