Page 1 of 1

UART capture

Posted: Sun Nov 04, 2018 8:26 pm
by cvargcal
Hi, I have this:

Code: Select all

void uart1_task(void *pvParameters){
	 char character;
	 char tem;
	    //struct cmdBuf cmdBuffer;
	   	keyboard_command_t keyboardCmd;

	    //Install UART driver, and get the queue.
		esp_err_t ret = ESP_OK;
		const uart_config_t uart_config = {
			.baud_rate = 9600,
			.data_bits = UART_DATA_8_BITS,
			.parity = UART_PARITY_DISABLE,
			.stop_bits = UART_STOP_BITS_1,
			.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
		};

		//update UART config
		ret = uart_param_config(UART_NUM_1, &uart_config);
		if(ret != ESP_OK)
		{
			//ESP_LOGE(EXT_UART_TAG,"external UART param config failed");
		}

		//set IO pins
		ret = uart_set_pin(UART_NUM_1, TXD1_PIN, RXD1_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
		if(ret != ESP_OK)
		{
			//ESP_LOGE(EXT_UART_TAG,"external UART set pin failed");
		}
	    uart_driver_install(UART_NUM_1, UART_FIFO_LEN * 2, UART_FIFO_LEN * 2, 0, NULL, 0);

	    //ESP_LOGI(EXT_UART_TAG,"external UART processing task started");
	    //cmdBuffer.state=CMDSTATE_IDLE;

	    while(1){

	            uart_read_bytes(UART_NUM_1, (uint8_t*) &character, 1, portMAX_DELAY); // read single byte

	    			 ESP_LOGI(CONSOLE_UART_TAG,"Uart1: %x",character);
	    			UID_RFID[i++]=character;


	    			          if(i==5) {                         // 00-00-00-00-'cheksum'
	    			               if((UID_RFID[0] ^ UID_RFID[1] ^ UID_RFID[2] ^ UID_RFID[3] ^ UID_RFID[4]) == 0){  // Valido el ID
	    			                  //IDcard.Enbytes[0] = UID_RFID[3]; //4
	    			                  //IDcard.Enbytes[1] = UID_RFID[2]; //3
	    			                  //IDcard.Enbytes[2] = UID_RFID[1]; //2
	    			                  //IDcard.Enbytes[3] = UID_RFID[0]; //1
	    			                  i=0x00;                         // Reincio contador
	    			                  //isCard=1;                       // Tarjeta presente
	    			            	   ESP_LOGI(CONSOLE_UART_TAG,"Tag OK: %s",UID_RFID);
	    			               }

	    			               else
	    			               {

	    			               i=0x00;                            // Reincio contador
	    			               //isCard=0x00;                       // Tarjeta invalida
	    			              memset(UID_RFID,NULL,sizeof(UID_RFID));
	    			               }
	    			              }

	        }
}
How print the buffer as string? this not work
ESP_LOGI(CONSOLE_UART_TAG,"Tag OK: %s",UID_RFID);

ESP_LOGI(CONSOLE_UART_TAG,"Tag OK: %x",UID_RFID[k]); if work.

I want capture every character for use this function:

Code: Select all

// ******* ASCCI to KEYBOARD 
uint16_t ToHidKeyboardScancode(char c){ 
      switch(c){ 
      // Hex 
         case 'A':   return(0x04); 
         case 'B':   return(0x05); 
         case 'C':   return(0x06); 
         case 'D':   return(0x07); 
         case 'E':   return(0x08); 
         case 'F':   return(0x09); 

         case '1':   return(0x1E); 
         case '2':   return(0x1F); 
         case '3':   return(0x20); 
         case '4':   return(0x21); 
         case '5':   return(0x22);  // 
         case '6':   return(0x23);  // 
         case '7':   return(0x24);  // 
         case '8':   return(0x25);  // 
         case '9':   return(0x26);  // 
         case '0':   return(0x27); 
      } 
      //if ((c>='a') && (c<='z')) return (c-'a'+'A'); 
      return(0); 

}