| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| cvargcal 
 
 
 Joined: 17 Feb 2015
 Posts: 134
 
 
 
			    
 
 | 
			
				| How send print in hex? |  
				|  Posted: Wed Apr 22, 2020 7:14 pm |   |  
				| 
 |  
				| I have this function, and I need send buffer in hex: 
 
  	  | Code: |  	  | uint8_t TCPClient_Send(char* data, uint16_t length){ 
 if( SIM800L_sendATCommand("AT+CIPSEND",">",3000)){
 for (uint16_t i = 0; i < length; i++){
 fprintf(uart2,"%02x",Data[i]);
 }
 
 fprintf(uart2,"%c",0x1A);
 }
 }
 | 
 
 This is the data that should be sent.
 
  	  | Quote: |  	  | 103D00044D51545404C2012C000541424344460008637661726763616C002061696F5F784A6562383365476E6C594145445667786C66797173754B4D74746B | 
 
 but instead the data arrive as string just like I sent...."103D00044D51545404C2012C0005414...."  why?
 
 
 
   
 I want to  do like made hercules.
 
 Last edited by cvargcal on Wed Apr 22, 2020 7:51 pm; edited 2 times in total
 |  | 
	
		|  | 
	
		| jeremiah 
 
 
 Joined: 20 Jul 2010
 Posts: 1401
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Apr 22, 2020 7:35 pm |   |  
				| 
 |  
				| fprintf sends strings.  Use fputc() instead to send it in raw binary/hex/integer form. |  | 
	
		|  | 
	
		| cvargcal 
 
 
 Joined: 17 Feb 2015
 Posts: 134
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Apr 22, 2020 8:33 pm |   |  
				| 
 |  
				|  	  | jeremiah wrote: |  	  | fprintf sends strings.  Use fputc() instead to send it in raw binary/hex/integer form. | 
 
 I used :
 
 
  	  | Code: |  	  | fputc(Data[i],uart2); | 
 
 but when print that way... I think the PIN RX uart is blocked because let to capture  data.
 
 if I print of other way the interruption dont blocked....
  |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Apr 22, 2020 11:34 pm |   |  
				| 
 |  
				| fprintf(uart2,"%c",0x1A); 
 Use instead:
 
 fprintf(uart2,"%02X",0x1A);
 
 Now that will just print the number in hex (as two digits).
 If you want the '0X', you use:
 
 fprintf(uart2,"0x%02X",0x1A);
 
 The 'X' in the format, can be lower case for 1a, or upper case for 1A.
 
 Using the leading '0', makes it always print both digits, so:
 
 00, 01, 02, 03... 0A, 0B etc..
 |  | 
	
		|  | 
	
		| cvargcal 
 
 
 Joined: 17 Feb 2015
 Posts: 134
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 23, 2020 12:01 am |   |  
				| 
 |  
				| Thanks  so much. 
 I found my problem.... i did printed fine the hex, but I think  in this header from packet it has a hex weird and as module gms it has echo activate so one character comeback a blocked the response module...
 |  | 
	
		|  | 
	
		|  |