<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43903/parallel-to-serial-converter</link><description>Hello everyone, 
 I write this post because I haven&amp;#39;t been able to find a solution to a problem I&amp;#39;m having to implement a parallel to serial converter. I am employing the nrf52 DK device. 
 My scheme of the circuit is the following one: 
 
 - Inputs </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 28 Feb 2019 14:24:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43903/parallel-to-serial-converter" /><item><title>RE: Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/thread/173513?ContentTypeID=1</link><pubDate>Thu, 28 Feb 2019 14:24:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c0bb74a-7869-41ab-9014-6d39a57cc0ba</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Why don&amp;#39;t you set the output pins in the&amp;nbsp;for (;;) function in main()? Using the interrupt handler requires some extra cycles as explained earlier. Regarding the question about Out1 and Out2, you could take a look at the fork mechanims of PPI.&lt;/p&gt;
&lt;p&gt;I&amp;nbsp;simplified the IRQHandler, but I don&amp;#39;t think it will make much difference regarding speed:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void optimized_TIMER2_IRQHandler(void)
{
	NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] = 0;	       //Clear compare register 0 event
	NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; 30);
	
	if(b[lect]){
		NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; 28) | (1UL &amp;lt;&amp;lt; 29);  
	}else{
		NRF_GPIO-&amp;gt;OUTCLR = (1UL &amp;lt;&amp;lt; 28) | (1UL &amp;lt;&amp;lt; 29);	
	}
	if(lect&amp;lt;7){
		lect++;
	}else{
		lect=0;
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/thread/173091?ContentTypeID=1</link><pubDate>Tue, 26 Feb 2019 15:44:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f530a552-9aac-4d38-a0c2-228e9a9456e6</guid><dc:creator>norbe13</dc:creator><description>&lt;p&gt;Thank you all for your help!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Finally I achieved that I wanted but only for 1 MHZ. I attach the code. I have to say that now (in the code is included) I need that Out has to be Out1 and Out2 with the same value but for two output pins. If somebody find a way to optimize the code, please tell me!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void GPIO_TIMER_Init(void)
{  

		
		nrf_gpio_cfg_output(28); //Out1
		nrf_gpio_cfg_output(29); //Out2
		nrf_gpio_cfg_output(30); //Enable
		

	
	//GPIOTE FOR FLAG SIGNAL
						nrf_gpio_cfg_input(17, NRF_GPIO_PIN_NOPULL); // Enable pullup on the GPIO
						NRF_GPIOTE-&amp;gt;CONFIG[0] = (GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos) | 
																		(GPIOTE_CONFIG_POLARITY_HiToLo &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos) | 
																		(17 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos);
	//GPIOTE FOR CLOCK SIGNAL
						nrf_gpio_cfg_input(22, NRF_GPIO_PIN_NOPULL); // Enable pullup on the GPIO
						NRF_GPIOTE-&amp;gt;CONFIG[1] = (GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos) | 
																		(GPIOTE_CONFIG_POLARITY_LoToHi &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos) | 
																		(22 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos); 

														
														
	NVIC_DisableIRQ(TIMER2_IRQn);
  NVIC_ClearPendingIRQ(TIMER2_IRQn);

//TIMER FOR CLOCK 

  NRF_TIMER2-&amp;gt;MODE = TIMER_MODE_MODE_Counter;              // Set the timer in Counter Mode
	NRF_TIMER2-&amp;gt;SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE0_CLEAR_Pos;
  NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;                             // clear the task first to be usable for later
	NRF_TIMER2-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_08Bit;		   //Set counter to 16 bit resolution
	NRF_TIMER2-&amp;gt;CC[0] = 1;                               //Set value for TIMER2 compare register 0
	

 NRF_TIMER2-&amp;gt;INTENSET = (TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos);
 NVIC_EnableIRQ(TIMER2_IRQn);
  
  //TIMER FOR ENABLE
	
	NRF_TIMER1-&amp;gt;MODE = TIMER_MODE_MODE_Counter;              // Set the timer in Counter Mode
	NRF_TIMER1-&amp;gt;SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE1_CLEAR_Pos) |
											 (TIMER_SHORTS_COMPARE1_STOP_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE1_STOP_Pos);
  NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;                             // clear the task first to be usable for later
	NRF_TIMER1-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_08Bit;		   //Set counter to 16 bit resolution
	NRF_TIMER1-&amp;gt;CC[1] = 8;                               //Set value for TIMER2 compare register 1 


	NRF_PPI-&amp;gt;CH[0].TEP = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_START; //Start TIMER2
	NRF_PPI-&amp;gt;CH[0].EEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[0];
	NRF_PPI-&amp;gt;CHEN |= PPI_CHEN_CH0_Enabled &amp;lt;&amp;lt; PPI_CHEN_CH0_Pos;

	NRF_PPI-&amp;gt;CH[1].TEP = (uint32_t)&amp;amp;NRF_TIMER1-&amp;gt;TASKS_START; //START TIMER1
	NRF_PPI-&amp;gt;CH[1].EEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[0];
	NRF_PPI-&amp;gt;CHEN |= PPI_CHEN_CH1_Enabled &amp;lt;&amp;lt; PPI_CHEN_CH1_Pos;

	NRF_PPI-&amp;gt;CH[2].TEP = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_COUNT; //COUNT TIMER2
	NRF_PPI-&amp;gt;CH[2].EEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[1];
	NRF_PPI-&amp;gt;CHEN |= PPI_CHEN_CH2_Enabled &amp;lt;&amp;lt; PPI_CHEN_CH2_Pos;
	
	NRF_PPI-&amp;gt;CH[3].TEP = (uint32_t)&amp;amp;NRF_TIMER1-&amp;gt;TASKS_COUNT; //COUNT TIMER1
	NRF_PPI-&amp;gt;CH[3].EEP = (uint32_t)&amp;amp;NRF_GPIOTE-&amp;gt;EVENTS_IN[1];
	NRF_PPI-&amp;gt;CHEN |= PPI_CHEN_CH3_Enabled &amp;lt;&amp;lt; PPI_CHEN_CH3_Pos;
	
	
	NRF_PPI-&amp;gt;CH[6].TEP = (uint32_t)&amp;amp;NRF_TIMER2-&amp;gt;TASKS_STOP; //STOP TIMER2
  NRF_PPI-&amp;gt;CH[6].EEP = (uint32_t)&amp;amp;NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1];
  NRF_PPI-&amp;gt;CHEN |= PPI_CHEN_CH6_Enabled &amp;lt;&amp;lt; PPI_CHEN_CH6_Pos;
	

	
}

void TIMER2_IRQHandler(void)
{
		NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] = 0;	       //Clear compare register 0 event
	
		
	
	if(lect&amp;lt;7)
    {
			
				if(b[lect]){
					NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; 30);
					NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; 28) | (1UL &amp;lt;&amp;lt; 29);  
					
				}
				else{
					NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; 30);
					NRF_GPIO-&amp;gt;OUTCLR = (1UL &amp;lt;&amp;lt; 28) | (1UL &amp;lt;&amp;lt; 29);
					
				}
				lect++;
				}
				else{
					if(b[lect]){
					NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; 30);
					NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; 28) | (1UL &amp;lt;&amp;lt; 29);  
					
				}
				else{
					NRF_GPIO-&amp;gt;OUTSET = (1UL &amp;lt;&amp;lt; 30);
					NRF_GPIO-&amp;gt;OUTCLR = (1UL &amp;lt;&amp;lt; 28) | (1UL &amp;lt;&amp;lt; 29);
					}
				lect=0;
    }
    
}

 int main(void)
{
	
	// VARIABLE INITIALIZATION 
      lect=0;
			NRF_GPIO-&amp;gt;OUTCLR = (1UL &amp;lt;&amp;lt; 30);
			
	
	 // WAIT FOR HFCLK START
			NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
			while(NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED != 1){}
				
			GPIO_TIMER_Init();

        for (;;)
    {
				
				NRF_GPIOTE-&amp;gt;EVENTS_IN[0]=0;
				
				
        if(NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1]){
				lect=0;
				NRF_GPIO-&amp;gt;OUTCLR = (1UL &amp;lt;&amp;lt; 30);}
				while(NRF_GPIOTE-&amp;gt;EVENTS_IN[0] != 1){}
					
				}
		
		}
    }

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/thread/172731?ContentTypeID=1</link><pubDate>Mon, 25 Feb 2019 11:58:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbe21b7b-bbdd-4196-b662-ff52d98c493f</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;You can try to configure two GPIOTE OUT tasks via two PPI channels - one for setting, another for clearing output, and switch between them using PPI.CHEN register. A number of mcu cycles will be about the same, but you will get synchronous switching done by hardware, and a &amp;quot;window&amp;quot; to prepare PPI.CHEN according to next bit. Another point to optimize - all hardware registers are defined as volatile, so try to save EVENTS_IN[0] into a variable instead of reading it twice in two if() statements - you will save some cycles.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/thread/172723?ContentTypeID=1</link><pubDate>Mon, 25 Feb 2019 10:28:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42ef6fce-9f5b-4aac-bdf8-a9bf97d74842</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;It seems like the project with polling is the best way to go, since you achieved a higher frequency than the one using the interrupt handler. I am not sure how to solve it using PPI and EasyDMA.&lt;/p&gt;
&lt;p&gt;In the code where you are polling the input, try switching out nrf_gpio_pin_toggle(..) with TASK_OUT[..], which will save you some clock cycles. First you need to create two different tasks, one for setting the pin low, and one for setting it high, then you call the appropriate task depending on b[a]. Also, turn on optimization when compiling your code, in order to make it a little faster.&lt;/p&gt;
[quote user="norbe13"]Another question that I have... what is the maximum frequency for a event_handler of GPIOTE?&amp;nbsp;[/quote]
&lt;p&gt;I have not calculated this, but it depends on the amount of code running in the interrupt handler. I think the interrupt latency on entry and the interrupt latency on exit is 12+10=22 cycles. If you add those cycles to the amount of cycles in the handler + everything running in the background, and eventually divide the CPU clock frequency (64MHz for the&lt;span&gt;&amp;nbsp;&lt;/span&gt;nRF52832) with the amount of cycles, you will get the frequency of the GPIOTE handler.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/thread/172167?ContentTypeID=1</link><pubDate>Wed, 20 Feb 2019 16:03:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af8b30f7-2111-49bd-9b7e-fee33914e772</guid><dc:creator>norbe13</dc:creator><description>&lt;p&gt;I have just achieve to sent the information that I need to transfer but a maximum clock frequency of 500 kHz. This is the code that I employ. When I employ higher frequencies than 500 kHz, for example 1 MHz, the output&amp;nbsp;code is correct, but the duration of the pulses is different for each value. I would like to know if there is a way to read a signal of 2 MHz by GPIO or GPIOTE and do and action related with a value of the RAM, Could I do something related with DMA? For example --&amp;gt; Clock --&amp;gt; GPIOTE --&amp;gt; DMA (read) --&amp;gt; RAM --&amp;gt; DMA (write) --&amp;gt; GPIOTE.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Another question that I have... what is the maximum frequency for a event_handler of GPIOTE?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void gpio_init(void)
{

	
	nrf_gpio_cfg_input(22, NRF_GPIO_PIN_NOPULL);

	NRF_GPIOTE-&amp;gt;CONFIG[0] =  (GPIOTE_CONFIG_POLARITY_LoToHi &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos)
                      | (22 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos)   
                      | (GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos);
	
}


/**
 * @brief Function for application main entry.
 */
int main(void)
{
	
		NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
		int a=7;
		bool b[8] = {1,0,1,0,1,0,1,0};
		
  
    nrf_drv_gpiote_init();
		nrf_gpio_cfg_output(28);

		gpio_init();;

    while (true)
    { 
			
			
			if(NRF_GPIOTE-&amp;gt;EVENTS_IN[0] &amp;amp;&amp;amp; a&amp;lt;7){
				NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
				if(b[a]){
					nrf_gpio_pin_set(28);
					a=a+1;
				}
				else{
					nrf_gpio_pin_clear(28);
					a=a+1;
				}}
			
				else if(NRF_GPIOTE-&amp;gt;EVENTS_IN[0] &amp;amp;&amp;amp; a==7)
				{ NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
				if(b[a]){
					nrf_gpio_pin_set(28);
					a=0;
				}
				else{
					nrf_gpio_pin_clear(28);
					a=0;
		}}





}}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/thread/172038?ContentTypeID=1</link><pubDate>Wed, 20 Feb 2019 08:37:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6c8d591-f32b-45c8-8e19-159d97ec7272</guid><dc:creator>norbe13</dc:creator><description>&lt;p&gt;Is not possible because you can&amp;#39;t change the clock of the SPI to 2 MHz&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/thread/171979?ContentTypeID=1</link><pubDate>Tue, 19 Feb 2019 20:12:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9317a1df-b7bf-4701-806f-d909e909bf40</guid><dc:creator>norbe13</dc:creator><description>&lt;p&gt;Do you mean this connection? FLAG --&amp;gt; GPIOTE (INPUT RISING EDGE) --&amp;gt; PPI --&amp;gt; SPI (MASTER). Because the Flag is a bit that comes from a custom IC that is High when you can write in their Serial to parallel register, and I don&amp;#39;t have anymore outputs from the IC.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Parallel to Serial Converter</title><link>https://devzone.nordicsemi.com/thread/171966?ContentTypeID=1</link><pubDate>Tue, 19 Feb 2019 17:59:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e8e26389-0b5b-482d-8b56-1b8778af0750</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Could you not just use the SPI peripheral ... ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>