<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックRe: LPC-Link2 High Speed ADC and DMA Interrupt?</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1536578#M50390</link>
    <description>&lt;P&gt;Hi Miguel,&lt;/P&gt;&lt;P&gt;Unfortunately, this did not resolve my issue. I have reviewed the user manual as well and it did not work. From LPCOpen, I tried numerous examples such as&amp;nbsp;periph_hsadc and&amp;nbsp;periph_dma_timertrig. Both examples did not help with my progress either.&lt;/P&gt;&lt;P&gt;Please let me know what you discover!&lt;/P&gt;</description>
    <pubDate>Wed, 12 Oct 2022 23:11:39 GMT</pubDate>
    <dc:creator>act642</dc:creator>
    <dc:date>2022-10-12T23:11:39Z</dc:date>
    <item>
      <title>LPC-Link2 High Speed ADC and DMA Interrupt?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1532249#M50322</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently using two LPC-Link2's (one as debug probe and one as the eval board).&lt;/P&gt;&lt;P&gt;My goal is to continuously send data from the ADC FIFO to a DMA buffer. Once the DMA buffer is full, I also want to use the DMA interrupt to send data through USB.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am not able to enter the DMA interrupt at all, and I was wondering if anyone else has gotten this to work? Please find my code for reference:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#include "board.h"
#include &amp;lt;stdio.h&amp;gt;
#include "libusbdev.h"
#ifdef __USE_CMSIS
#include "LPC43xx.h"
#endif
// code from forum: https://community.nxp.com/t5/LPC-Microcontrollers/How-to-achieve-80MHz-using-DMA-from-LPC4370-s-HSADC/m-p/531525/page/1
// DMA buffer -&amp;gt; 4095 -&amp;gt; 32-bits -&amp;gt; packed -&amp;gt; 4095*2
// ADC FIFO
#define VADC_DMA_WRITE  7
#define VADC_DMA_READ   8
#define DMA_TRANSFER_SIZE 100 // max. 4095
uint32_t sample[DMA_TRANSFER_SIZE];

//DMA_TransferDescriptor_t arrayLLI[1];
//static GPDMA_LLI_Type DMA_Stuff[1];

/*
 * High speed ADC is set up appropriately
 */
void ADC_init(void) {
	Chip_Clock_SetDivider(CLK_IDIV_A, CLKIN_USBPLL, 2); /* Source DIV_A from USB0PLL, and set divider to 2 (Max div value supported is 4) [IN 480 MHz; OUT 240 MHz */
	Chip_Clock_SetDivider(CLK_IDIV_B, CLKIN_IDIVA, 3); /* Source DIV_B from DIV_A, [IN 240 MHz; OUT 80 MHz */
	Chip_Clock_SetBaseClock(CLK_BASE_ADCHS, CLKIN_IDIVB, true, false); /* Source ADHCS base clock from DIV_B */

	Chip_HSADC_FlushFIFO(LPC_ADCHS);
	Chip_HSADC_DeInit(LPC_ADCHS);

	NVIC_DisableIRQ(ADCHS_IRQn);
	LPC_ADCHS-&amp;gt;INTS[0].CLR_EN = 0x7F; 			// disable interrupt 0
	LPC_ADCHS-&amp;gt;INTS[0].CLR_STAT = 0x7F; 		// clear interrupt status
	while (LPC_ADCHS-&amp;gt;INTS[0].STATUS &amp;amp; 0x7D); 	// wait for status to clear, have to exclude FIFO_EMPTY

	LPC_ADCHS-&amp;gt;INTS[1].CLR_EN = 0x7F;
	LPC_ADCHS-&amp;gt;INTS[1].CLR_STAT = 0x7F;
	while (LPC_ADCHS-&amp;gt;INTS[1].STATUS &amp;amp; 0x7D);

	LPC_ADCHS-&amp;gt;POWER_DOWN = 0; // disable power down
	LPC_ADCHS-&amp;gt;FLUSH = 1;	   // clear fifo

	/* Initialize HSADC */
	Chip_HSADC_Init(LPC_ADCHS);	   // initialize

	LPC_ADCHS-&amp;gt;FIFO_CFG = (0x0 &amp;lt;&amp;lt; 0) | /* UNPACKED */
						  (0x8 &amp;lt;&amp;lt; 1);  /* FIFO_LEVEL */

	LPC_ADCHS-&amp;gt;DSCR_STS = (0 &amp;lt;&amp;lt; 0) |   /* ACT_TABLE:        0=table 0 is active, 1=table 1 is active */
							(0 &amp;lt;&amp;lt; 1);  /* ACT_DESCRIPTOR:   ID of the descriptor that is active */


	LPC_ADCHS-&amp;gt;DESCRIPTOR[0][0] = (2 &amp;lt;&amp;lt; 0) | /* CHANNEL_NR:    0=convert input 0, 1=convert input 1, ..., 5=convert input 5 */
									(0 &amp;lt;&amp;lt; 3) | /* HALT:          0=continue with next descriptor after this one, 1=halt after this and restart at a new trigger */
									(0 &amp;lt; 4)  | /* INTERRUPT:     1=raise interrupt when ADC result is available */
									(0 &amp;lt;&amp;lt; 5) | /* POWER_DOWN:    1=power down after this conversion */
									(1 &amp;lt;&amp;lt; 6) | /* BRANCH:        0=continue with next descriptor (wraps around after top) */
									/*                1=branch to the first descriptor in this table */
									/*                2=swap tables and branch to the first descriptor of the new table */
									/*                3=reserved (do not store sample). continue with next descriptor (wraps around the top) */
									(0x95 &amp;lt;&amp;lt; &lt;LI-EMOJI id="lia_smiling-face-with-sunglasses" title=":smiling_face_with_sunglasses:"&gt;&lt;/LI-EMOJI&gt; | /* MATCH_VALUE:   Evaluate this descriptor when descriptor timer value is equal to match value */
									(0 &amp;lt;&amp;lt; 22) 	| /* THRESHOLD_SEL: 0=no comparison, 1=THR_A, 2=THR_B */
									(1 &amp;lt;&amp;lt; 24) 	| /* RESET_TIME:    1=reset descriptor timer */
									(1 &amp;lt;&amp;lt; 31); 	  /* UPDATE_TABLE:  1=update table with all 8 descriptors of this table */

	LPC_ADCHS-&amp;gt;CONFIG = /* configuration register */
							(1 &amp;lt;&amp;lt; 0) | /* TRIGGER_MASK:     0=triggers off, 1=SW trigger, 2=EXT trigger, 3=both triggers */
							(0 &amp;lt;&amp;lt; 2) | /* TRIGGER_MODE:     0=rising, 1=falling, 2=low, 3=high external trigger */
							(0 &amp;lt;&amp;lt; 4) | /* TRIGGER_SYNC:     0=no sync, 1=sync external trigger input */
							(0 &amp;lt;&amp;lt; 5) | /* CHANNEL_ID_EN:    0=don't add, 1=add channel id to FIFO output data */
							(0x90 &amp;lt;&amp;lt; 6); /* RECOVERY_TIME:    ADC recovery time from power down, default is 0x90 */

	uint8_t DGEC = 0xE; // must match CRS (Table 1133) 0x4 = 80 MSPS thus 0xE

	// set all DGEC to 0xE
	LPC_ADCHS-&amp;gt;ADC_SPEED = (DGEC &amp;lt;&amp;lt; 16)
						| (DGEC &amp;lt;&amp;lt; 12)
						| (DGEC &amp;lt;&amp;lt; 8)
						| (DGEC &amp;lt;&amp;lt; 4)
						| (DGEC);

	//  For AC coupling, the DC biasing is generated internally by setting DCINNEG= 1 and DCINPOS= 1.
	//	generated internally by setting DCINNEG = 1 and DCINPOS = 1.
	LPC_ADCHS-&amp;gt;POWER_CONTROL = (0x4) /* CRS, current power vs speed programming*/;
							(1 &amp;lt;&amp;lt; 4) |      /* DCINNEG:      0=no dc bias, 1=dc bias on vin_neg slide */
							(0 &amp;lt;&amp;lt; 10) |     /* DCINPOS:      0=no dc bias, 1=dc bias on vin_pos slide */
							(0 &amp;lt;&amp;lt; 16) |     /* TWOS:         0=offset binary, 1=two's complement */
							(1 &amp;lt;&amp;lt; 17) |     /* POWER_SWITCH: 0=ADC is power gated, 1=ADC is active */
							(1 &amp;lt;&amp;lt; 18);      /* BGAP_SWITCH:  0=ADC bandgap reg is power gated, 1=ADC bandgap is active */
	NVIC_EnableIRQ(ADCHS_IRQn);

}

/*
 * Set up GPDMA
 */
void GPDMA_init(void) {
//    /* DMA controller configuration */
	Chip_GPDMA_DeInit(LPC_GPDMA);
	Chip_GPDMA_Init(LPC_GPDMA);
	
	NVIC_DisableIRQ(DMA_IRQn);
	LPC_GPDMA-&amp;gt;CONFIG = 0x00;	// Disable configuration

	/* Clear all DMA interrupt and error flag */
	LPC_GPDMA-&amp;gt;INTTCCLEAR = 0xFF; //clears channel terminal count interrupt
	LPC_GPDMA-&amp;gt;INTERRCLR = 0xFF; //clears channel error interrupt.

	uint8_t ch_no = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, 0);
	Chip_GPDMA_ChannelCmd(LPC_GPDMA, ch_no, ENABLE);

	/* Setup the DMAMUX */
	LPC_CREG-&amp;gt;DMAMUX &amp;amp;= ~(0x3 &amp;lt;&amp;lt; (VADC_DMA_WRITE * 2));
	LPC_CREG-&amp;gt;DMAMUX |= 0x3 &amp;lt;&amp;lt; (VADC_DMA_WRITE * 2); /* peripheral 7 vADC Write(0x3) */
	LPC_CREG-&amp;gt;DMAMUX &amp;amp;= ~(0x3 &amp;lt;&amp;lt; (VADC_DMA_READ * 2));
	LPC_CREG-&amp;gt;DMAMUX |= 0x3 &amp;lt;&amp;lt; (VADC_DMA_READ * 2); /* peripheral 8 vADC read(0x3) */

	LPC_GPDMA-&amp;gt;CONFIG = 0x01; // Enable configuration
	while (!(LPC_GPDMA-&amp;gt;CONFIG &amp;amp; 0x01)); //Wait until GPDMA is enabled

	// Initialize LPC_GPDMA, ch_no = 0
	// Source, ADC FIFO
	// Destination -&amp;gt; sample buffer
	// LLI back to 0 -&amp;gt; circular?
	LPC_GPDMA-&amp;gt;CH[ch_no].SRCADDR = (uint32_t) &amp;amp;LPC_ADCHS-&amp;gt;FIFO_OUTPUT[0];
	LPC_GPDMA-&amp;gt;CH[ch_no].DESTADDR = ((uint32_t) &amp;amp;sample);
	LPC_GPDMA-&amp;gt;CH[ch_no].LLI = 0; //Configuration registers for channel 0

	// Refer to page 525 in the manual
	LPC_GPDMA-&amp;gt;CH[ch_no].CONTROL = (DMA_TRANSFER_SIZE)   // transfer size
								| (0x03 &amp;lt;&amp;lt; 12)  // src burst size = 16
								| (0x03 &amp;lt;&amp;lt; 15)  // dst burst size = 16
								| (0x2 &amp;lt;&amp;lt; 18)  	// src transfer width - 32-bit
								| (0x2 &amp;lt;&amp;lt; 21)  	// dst transfer width - 32 bit
								| (0x1 &amp;lt;&amp;lt; 24)  	// src AHB master select
								| (0x1 &amp;lt;&amp;lt; 25)  	// dst AHB master select
								| (0x0 &amp;lt;&amp;lt; 26) 	// src increment: 0, src address not increment after each trans
								| (0x1 &amp;lt;&amp;lt; 27) 	// dst increment: 1, dst address NOT increment after each trans
								| (0x1 &amp;lt;&amp;lt; 31); 	// terminal count interrupt enable bit: 1, enabled

	LPC_GPDMA-&amp;gt;CONFIG = (0x1 &amp;lt;&amp;lt; 0) |          	// Enable bit
						(VADC_DMA_READ &amp;lt;&amp;lt; 1) |  // SRCPERIPHERAL - set to 8 - VADC (0x8)
						(0x0 &amp;lt;&amp;lt; 6) |        	// Destination peripheral - memory - no setting
						(0x6 &amp;lt;&amp;lt; 11) |  			// Flow control - peripheral to memory - DMA control
						(0x1 &amp;lt;&amp;lt; 14) |          	// Int error mask
						(0x1 &amp;lt;&amp;lt; 15);            // ITC - term count error mask

	NVIC_SetPriority(DMA_IRQn, 0x02);
	NVIC_EnableIRQ(DMA_IRQn);
	LPC_GPDMA-&amp;gt;CH[ch_no].CONFIG = (0x1 &amp;lt;&amp;lt; 0); 	// enable bit, 1 enable, 0 disable
}

void DMA_IRQHandler(void) {
	Board_LED_Toggle(0);
}

int main(void) {
	SystemCoreClockUpdate();
	Board_Init();
	Chip_USB0_Init(); /* Initialize the USB0 PLL to 480 MHz */
	ADC_init();
	GPDMA_init();
	libusbdev_init(USB_STACK_MEM_BASE, USB_STACK_MEM_SIZE);

	// Initialize sample array to 32 1's, F = 1111
	for (int i = 0; i &amp;lt; DMA_TRANSFER_SIZE; i++) {
		sample[i] = 0xFFFFFFFF;
	}

	Chip_HSADC_SWTrigger(LPC_ADCHS); // start DMA

	while (libusbdev_Connected() == 0);
	while (1) {
		__WFI();
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 17:00:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1532249#M50322</guid>
      <dc:creator>act642</dc:creator>
      <dc:date>2022-10-04T17:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: LPC-Link2 High Speed ADC and DMA Interrupt?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1536433#M50389</link>
      <description>&lt;P style="margin: 0in; font-family: Calibri; font-size: 16.0pt;"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;HI &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/205243"&gt;@act642&lt;/a&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 16.0pt;"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;I am Miguel.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 16.0pt;"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;I've been investigating your issue and the problem with the interrupt could the initialization process, please check chapter &lt;SPAN&gt;21.8.1.7 Programming a DMA channel&lt;/SPAN&gt; step 2 and the &lt;SPAN&gt;21.8.2.1 Peripheral-to-memory or memory-to-peripheral DMA flow &lt;/SPAN&gt;on the LPC4370 user manual.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 16.0pt;"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;You could also use the DMA example from &lt;SPAN&gt;LPCOpen&lt;/SPAN&gt;. The path on your system should be like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 16.0pt;"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;&lt;SPAN&gt;"MCUXpressoIDE_11.6.0_8187\ide\plugins\com.nxp.mcuxpresso.tools.wizards_11.6.0.202112161359\Examples\LPCOpen"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 16.0pt;"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Let me know if this resolve your issue.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 16.0pt;"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Best Regards, Miguel.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 18:04:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1536433#M50389</guid>
      <dc:creator>Miguel04</dc:creator>
      <dc:date>2022-10-12T18:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: LPC-Link2 High Speed ADC and DMA Interrupt?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1536578#M50390</link>
      <description>&lt;P&gt;Hi Miguel,&lt;/P&gt;&lt;P&gt;Unfortunately, this did not resolve my issue. I have reviewed the user manual as well and it did not work. From LPCOpen, I tried numerous examples such as&amp;nbsp;periph_hsadc and&amp;nbsp;periph_dma_timertrig. Both examples did not help with my progress either.&lt;/P&gt;&lt;P&gt;Please let me know what you discover!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 23:11:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1536578#M50390</guid>
      <dc:creator>act642</dc:creator>
      <dc:date>2022-10-12T23:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: LPC-Link2 High Speed ADC and DMA Interrupt?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1539539#M50440</link>
      <description>&lt;P style="margin: 0in; font-family: Calibri; font-size: 14.0pt;"&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/205243"&gt;@act642&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 14.0pt;"&gt;I've compared your code with the initialization of the examples and I don’t see you restart the CONFIG of the channel, could you verify if this is the issue?&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 14.0pt;"&gt;Also, Could you provide me more details, please.&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 14.0pt;"&gt;How do you want to trigger de DMA?&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 14.0pt;"&gt;Is the DMA getting triggered (on registers)?&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 14.0pt;"&gt;Does the examples from LPCOpen worked?&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 14.0pt;"&gt;I'll let you know if I find something else.&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 14.0pt;"&gt;Miguel.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 17:49:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC-Link2-High-Speed-ADC-and-DMA-Interrupt/m-p/1539539#M50440</guid>
      <dc:creator>Miguel04</dc:creator>
      <dc:date>2022-10-18T17:49:22Z</dc:date>
    </item>
  </channel>
</rss>

