Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How can print fr value on UART ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,442
Guys,

How can I print fr to UART ?
Code:
 fr = f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
HAL_UART_Transmit(&huart1, fr, 32, 1); // Debug

I got this error :
..\Src\main.c(85): error: #167: argument of type "FRESULT" is incompatible with parameter of type "uint8_t *"
 

While someone can know exactly how to solve this error, most of us will need some more context. It seems that you are feeding the function a data type that it's not expecting.

Which line of code is generating the error? You should check on the prototype of the function which data type it uses.
 

I want to transmit "res" into UART buffer :

Code:
FRESULT f_open (
	FIL* fp,			/* Pointer to the blank file object */
	const TCHAR* path,	/* Pointer to the file name */
	BYTE mode			/* Access mode and file open mode flags */
)
{
	FRESULT res;

I want to print "res" to UART buffer
Code:
void Transmit_String_ff(unsigned char *s)
{
  HAL_UART_Transmit(&huart1, s, strlen(s), 1000); // As a pointer, with a length
}

I can't do

Transmit_String_ff(res)

I got this error,
error: #167: argument of type "FRESULT" is incompatible with parameter of type "unsigned char *"

How can I fix it ? thanks
 
Last edited:

Show the code of FRESULT type.
Code:
/* File function return code (FRESULT) */

typedef enum {
	FR_OK = 0,				/* (0) Succeeded */
	FR_DISK_ERR,			/* (1) A hard error occurred in the low level disk I/O layer */
	FR_INT_ERR,				/* (2) Assertion failed */
	FR_NOT_READY,			/* (3) The physical drive cannot work */
	FR_NO_FILE,				/* (4) Could not find the file */
	FR_NO_PATH,				/* (5) Could not find the path */
	FR_INVALID_NAME,		/* (6) The path name format is invalid */
	FR_DENIED,				/* (7) Access denied due to prohibited access or directory full */
	FR_EXIST,				/* (8) Access denied due to prohibited access */
	FR_INVALID_OBJECT,		/* (9) The file/directory object is invalid */
	FR_WRITE_PROTECTED,		/* (10) The physical drive is write protected */
	FR_INVALID_DRIVE,		/* (11) The logical drive number is invalid */
	FR_NOT_ENABLED,			/* (12) The volume has no work area */
	FR_NO_FILESYSTEM,		/* (13) There is no valid FAT volume */
	FR_MKFS_ABORTED,		/* (14) The f_mkfs() aborted due to any parameter error */
	FR_TIMEOUT,				/* (15) Could not get a grant to access the volume within defined period */
	FR_LOCKED,				/* (16) The operation is rejected according to the file sharing policy */
	FR_NOT_ENOUGH_CORE,		/* (17) LFN working buffer could not be allocated */
	FR_TOO_MANY_OPEN_FILES,	/* (18) Number of open files > _FS_SHARE */
	FR_INVALID_PARAMETER	/* (19) Given parameter is invalid */
} FRESULT;

It's part of ChanFATFs
 

Try this.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
unsigned int res;
char sprintf_buffer[20];
 
void main() {
 
    while(1) {
        res = f_open (...);
        sprintf(&sprintf_buffer, "%5u", res);
        
    }
}

 

Try this.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
unsigned int res;
char sprintf_buffer[20];
 
void main() {
 
    while(1) {
        res = f_open (...);
        sprintf(&sprintf_buffer, "%5u", res);
        
    }
}


Ok I'll try

- - - Updated - - -

I got this error :
Code:
..\Src\main.c(97): error:  #167: argument of type "unsigned char (*)[20]" is incompatible with parameter of type "char *restrict"
 

Getting error with my code ?

Post code of line 97 of main.c file.
 

Try this


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
unsigned int res;
unsigned char sprintf_buffer[20];
 
void main() {
 
    while(1) {
        res = f_open (...);
        sprintf(&sprintf_buffer, "%5u", res);
        
    }
}



What Compiler are you using ? What MCU ?
 

it gives me the same result
Code:
..\Src\main.c(97): error:  #167: argument of type "unsigned char (*)[20]" is incompatible with parameter of type "char *restrict"

Code:
	unsigned int res;
  unsigned char sprintf_buffer[20];
sprintf(&sprintf_buffer, "%5u", res);

I'm using Keil MDK, MCU = STM32

Any ideas ?
 

sprintf usage in Keil

https://www.keil.com/support/man/docs/c51/c51_sprintf.htm

**broken link removed**

Try


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
unsigned int res;
char sprintf_buffer[50];
 
void main() {
 
    while(1) {
        res = f_open (...);
        sprintf(sprintf_buffer, "%5u", res);
        
    }
}

 

it can be compiled but I can not see anything on serial buffer, code :
Code:
res=f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
				Transmit_String("F_OPEN result:\n");
				sprintf(sprintf_buffer, "%5u", res);

At the buffer :
Code:
F_OPEN result:
 

Please post your full code or zip and post your complete Keil project file. I need to see the USART transmit code. Is baudrate correct ? Have you printed test string to see if UART is working properly ?


Code C - [expand]
1
2
3
4
res = f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
sprintf(sprintf_buffer, "%5u", res);
strcat(sprintf_buffer, "\r\n");
Transmit_String(sprintf_buffer);



Assuming Transmit_String() function takes one string argument. Please post the complete code of Transmit_String() function.

Show UART initialization code. What baudrate are you using ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top