Write File and serial speed

Platform for Telematic Applications
Post Reply
maze38
Posts: 9
Joined: Tue 29. Nov 2016, 08:45

Write File and serial speed

Post by maze38 » Tue 29. Nov 2016, 09:21

Hi, I try to write a text file on the SD Card, but I have a problem with f_open command.

Code: Select all

xsprintf((char*)nameBuff,"trc%02u_%02u_%04u_%02uh%02um%02us.trx",
	time.day,time.month,time.year+2000,time.hour,time.min,time.sec);
res = f_open(&logFile,(char*)nameBuff,(FA_CREATE_NEW | FA_WRITE));
Where xprintf is a function used by another Peak solution.

Do you have a full example (I don't find the log.c file witch save a kml file).
I have another question about the serial port. I find several speed values but I need to configurate the serial port to 38400 baud. Is it possible ?

Thanks
Best regards.
Last edited by M.Gerber on Tue 29. Nov 2016, 10:39, edited 1 time in total.
Reason: Inserted [code] tags for better readability.

S.Michaelsen
Hardware Development
Hardware Development
Posts: 73
Joined: Fri 10. Sep 2010, 13:11

Re: Write File and serial speed

Post by S.Michaelsen » Tue 29. Nov 2016, 10:55

Hi,

the log.c is part of the libraries. The file is opened like

Code: Select all

//--------------------------------------------------------------------------
// FAT file system structure
//--------------------------------------------------------------------------
// File system object for each logical drive
static MEM_LOC_USBRAM ( FATFS fatfs[_DRIVES] );
// File objects
static MEM_LOC_USBRAM ( FIL logFile ) = {0};
.
.
.
res =  FR_NOK;
while(i_file<=MAX_FL_CNT){
	if(!(res==FR_OK) ){
		sprintf((char*)nameBuff,"trc%04d.kml",i_file);
		res = f_open(&logFile,(char*)nameBuff,( FA_CREATE_NEW | FA_WRITE));
		if(i_file==MAX_FL_CNT && res==0x08)
			res = f_open(&logFile,(char*)nameBuff,( FA_CREATE_ALWAYS | FA_WRITE));	
	}
	i_file++;
}	
.
.
.

//Write the header information into the file
res = f_write(&logFile, FL_HEADER, sizeof(FL_HEADER)-1,(UINT *) &bw); //Don't write the \0
if((bw < (sizeof(FL_HEADER)-1) )|| res)
{
	//Error while writing 
	logState = LOG_ERROR;
	break;
}
//Set the file size
fileSize = logFile.fsize;

//Update the file system
f_sync(&logFile);
.
.
.

Only the defined rates can be set using the library functions. If you need other baude rates you'd need to set the according UART registers (UXDLL, UXDLM, UXFDR for 72MHz Clock) to the values that are required for you speed.

Best Regards,
Stephan

maze38
Posts: 9
Joined: Tue 29. Nov 2016, 08:45

Re: Write File and serial speed

Post by maze38 » Tue 29. Nov 2016, 15:53

Thanks for your reply.

For the serial port speed, do you have an example.
I don't know how to set the according UART registers (UXDLL, UXDLM, UXFDR for 72MHz Clock).

Thanks

S.Michaelsen
Hardware Development
Hardware Development
Posts: 73
Joined: Fri 10. Sep 2010, 13:11

Re: Write File and serial speed

Post by S.Michaelsen » Wed 30. Nov 2016, 09:06

Something like

Code: Select all

VICIntEnClr |= (1<<29); //Disable interrupt UART3
tmp = U3LCR;
U3LCR = 0x80 | tmp; // DLAB=1 , enable writeaccess to divisor latch register
U3DLL = UDLL;
U3DLM = UDLM;
U3FDR = (MulVal<<4) | (DivAddVal&0xF);
U3LCR = tmp;  // DLAB=0 , disable writeaccess to divisor latch register
VICIntEnable |= (1<<29); //Interrupt Enable UART3
should do the trick. UDLL, UDLM, MulVal and DivAddVal are the values you've calculated for your baudrate. Note that the UART might be initialized by some library functions before you use them. So it is possible that there are outputs on the UART with 115,2k anyway before you renitialize it.

BR,
Stephan

maze38
Posts: 9
Joined: Tue 29. Nov 2016, 08:45

Re: Write File and serial speed

Post by maze38 » Thu 1. Dec 2016, 12:42

Thanks, but i don't really understand where to put this part of code and how to calulated UDLL, UDLM, MulVal and DivAddVal values.
is it possible to have a library with more baud rates (38400 baud for us).

Thanks

S.Michaelsen
Hardware Development
Hardware Development
Posts: 73
Joined: Fri 10. Sep 2010, 13:11

Re: Write File and serial speed

Post by S.Michaelsen » Thu 1. Dec 2016, 13:33

Well, I'd recommand to create an own function and call it at a point before you plan to use the UART.
About the values the LPC controllers user manual section about UART should give you an example how to calculate the needed values.
No sorry, unfotunately it is not possible.

BR,
Stphan

maze38
Posts: 9
Joined: Tue 29. Nov 2016, 08:45

Re: Write File and serial speed

Post by maze38 » Thu 1. Dec 2016, 16:10

It's work fine. There is a excel file in the product CD to calculate the needed values.

Thanks,

Post Reply