This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to use p0.02 for digital output

Hi,

This is strange,  I am not being able use p0.02 for digital output from sensors on nrf52840-DK but I am able to use all other analog pins for digital output (p0.03, p0.04 etc ..).

Attached is the code snippet where if i use #define DHT11_ONE_WIRE_INPUT_PIN  2 , it will not give readings but if i use  #define DHT11_ONE_WIRE_INPUT

#define DHT11_ONE_WIRE_INPUT_PIN	4


uint8_t bits[5];
int8_t dht11_dat[5]; 

#define DHTLIB_TIMEOUT 2

unsigned char DHT11_READ_1_BYTES_DATA(void);
void DHT11_DIR_INPUT(void);
void DHT11_DIR_OUTPUT(void);
void DHT11_START_SEQUENCE(void);
char DHT11_READ_5_BYTES_DATA(void);
unsigned long int ip;

void Convert_Humidity_Temperature_Values(unsigned char byte1);
void DHT_task_callback(void);



unsigned char decimal_value3, decimal_value2,decimal_value1;
unsigned long int Count_micro_second = 0;
unsigned long int test_start_seq1;
unsigned long int test_start_seq2;
unsigned long int test_start_seq3;

unsigned char Humidity_Int;
unsigned char Humidity_DEC;
unsigned char TEMPERATURE_Int;
unsigned char TEMPERATURE_DEC;
unsigned char CHECKSUM;
unsigned char err;
unsigned int TEMPERATURE_VALUE;
unsigned int HUMIDITY_VALUE;

void DHT_task_callback(void)
{
		
				ret_code_t err_code;
				
				
						
						NRF_LOG_INFO("get first data\n");
						printf("get first data\n");
						DHT11_START_SEQUENCE();
						DHT11_READ_5_BYTES_DATA();
	
						nrf_delay_ms(500);
				
}


void DHT11_START_SEQUENCE(void)
{
			DHT11_DIR_OUTPUT();

			nrf_gpio_pin_write(DHT11_ONE_WIRE_INPUT_PIN, level_1);
			//DHT11_ONE_WIRE_OUTPUT_PIN = 1;

			nrf_gpio_pin_write(DHT11_ONE_WIRE_INPUT_PIN, level_0);
			nrf_delay_ms(25);
			//ets_delay_us(22000);


			nrf_gpio_pin_write(DHT11_ONE_WIRE_INPUT_PIN, level_1);
			//	Delay_micro_second(30);
				nrf_delay_us(30);


			DHT11_DIR_INPUT();


		Count_micro_second = 0;
			//while(DHT11_ONE_WIRE_INPUT_PIN==0)
		while(nrf_gpio_pin_read(DHT11_ONE_WIRE_INPUT_PIN)==0)
		{

			//	printf("waiting for make line high by dht11\n");
                         Count_micro_second++;
			nrf_delay_us(1);

                        if(Count_micro_second > 100)
                        {break;}
		}
                      
                        Count_micro_second = 0;

		test_start_seq2 = Count_micro_second;

		Count_micro_second = 0;
			//	while(DHT11_ONE_WIRE_INPUT_PIN==1)
		while(nrf_gpio_pin_read(DHT11_ONE_WIRE_INPUT_PIN)==1)
		{
					//printf("waiting for make line low by dht11\n");
                                         Count_micro_second++;
				nrf_delay_us(1);

                                 if(Count_micro_second > 100)
                        {break;}
		}

                        Count_micro_second = 0;
	
		test_start_seq3 = Count_micro_second;
       }




unsigned char DHT11_READ_1_BYTES_DATA(void)
{

			unsigned int i=0;
			unsigned char Return_Value=0;
                        Count_micro_second = 0;

			for(i=0;i<8;i++)
			{
						Return_Value = Return_Value << 1;

					

                              
					while((nrf_gpio_pin_read(DHT11_ONE_WIRE_INPUT_PIN)) == 0)
					{
								                Count_micro_second++;
										nrf_delay_us(5);
                                                                              
                                                                               if(Count_micro_second > 100)
                                                                               {break;}
                                                                    
				         }
                                                    Count_micro_second = 0;

                                
					

					while((nrf_gpio_pin_read(DHT11_ONE_WIRE_INPUT_PIN))==1)
					{
								Count_micro_second++;
								nrf_delay_us(5);
                                                                 if(Count_micro_second > 100)
                                                                               {break;}
					}

					if(Count_micro_second<7)
					{	
									
									Return_Value = Return_Value | 0;
					}
					else
					{
								Return_Value = Return_Value | 1;
					}		
			}
//		printf("return_value=%c\n",Return_Value);

	return Return_Value;

}

void DHT11_DIR_INPUT(void)
{
				nrf_gpio_cfg_input(DHT11_ONE_WIRE_INPUT_PIN, NRF_GPIO_PIN_PULLUP);
}

void DHT11_DIR_OUTPUT(void)
{
				nrf_gpio_cfg_output(DHT11_ONE_WIRE_INPUT_PIN);
				//DHT11_ONE_WIRE_DIR = 1;
}

char DHT11_READ_5_BYTES_DATA(void)
{
			
				
				Humidity_Int = DHT11_READ_1_BYTES_DATA();
				Humidity_DEC = DHT11_READ_1_BYTES_DATA();
				TEMPERATURE_Int = DHT11_READ_1_BYTES_DATA();
				TEMPERATURE_DEC = DHT11_READ_1_BYTES_DATA();
				CHECKSUM = DHT11_READ_1_BYTES_DATA();
//				printf("datas = %c %c\n",Humidity_Int,TEMPERATURE_Int);

				if (((Humidity_Int + Humidity_DEC + TEMPERATURE_Int + TEMPERATURE_DEC) & 0xff) != CHECKSUM) 
				{

					NRF_LOG_INFO("got wrong values\n");
						printf("got wrong values\n");
					return 1;
				}
				else
				{
					NRF_LOG_INFO("got values\n");
                                        uint16_t humidity_bin = (Humidity_Int << 8) | (Humidity_DEC);
                                        uint16_t temp_bin = (TEMPERATURE_Int << 8) | (TEMPERATURE_DEC);
					printf("got values\n");
                                        
                                        printf("Humidity1 %d",humidity_bin );
                                        printf("Temperature1 %d", temp_bin );
                                        value[4] = (humidity_bin & 0xFF00) >> 8;                                    
                                        value[5] = (humidity_bin & 0x00FF);
                                        value[6] = (temp_bin & 0xFF00) >> 8;                                    
                                        value[7] = (temp_bin & 0x00FF);
                                        NRF_LOG_INFO("value5: %d     ",value[5]  );
                                       

                                       
                                       // printf("Humidity %d",Humidity_Int + Humidity_DEC );
                                       // printf("Temperature %d",TEMPERATURE_Int + TEMPERATURE_DEC );
					return err;
				}
}



void Convert_Humidity_Temperature_Values(unsigned char byte1)
{

			unsigned char intermediate_value1=0;                              //Varible required while converting the hex value to decimal value
				/*******************************************************************************
				Procedure to convert 8bit hex value to equivalent BCD value
				*******************************************************************************/
			decimal_value3=(byte1/100);
			intermediate_value1=byte1-(100*decimal_value3);
			decimal_value2=(intermediate_value1/10);
			decimal_value1=intermediate_value1-(10*decimal_value2);
}
_PIN  3, it will. 

Please suggest!

Thanks,

Arshdeep 

Related