Hi there,
I have some very (!) limited experience of using Keil uVision with an ST STM32 Nucleo-32 STM32L432KC development board. In the past I've written some "dummy" data, in the form of a series of decimal numbers, to a variable and then transmitted that using the UART Tx pin. That's more or less the extent of my experience.
What I'd like to do now is transmit a .txt file from one PC to another, via two of those microcontrollers and their serial pins:
1) read a .TXT file saved on a (Windows) PC that the Transmitting micro-controller is connected to.
2) transmit this data using the serial UART pin.
I guess steps 1) & 2) would require converting the ASCII characters to binary bits...
3) At the Receiver micro-controller, I'd like to read this serial data, convert it back into text and finally...
4) Save the received text as a .TXT file.
------ By the way, the .txt files could be relatively large (e.g. 5 Mb) so I may not be able to store all the received data in memory before dumping it to the .txt file.
Is this something that is possible to do using uVision? If so, would anyone be able to give some pointers on how to read and write .txt files?
Many thanks in advance and apologies if my question is too vague or off-topic for these forums.
Jonathan
"What I'd like to do now is transmit a .txt file from one PC to another, via two of those microcontrollers"
You mean something like this:
PC1 Nucleo 1 Nucleo 2 PC2 +-----+ +--------+ +--------+ +-----+ | | | | | | | | | Tx +---->+ Rx Tx +---->+ Rx Tx +---->+ Rx | | | | | | | | | +-----+ +--------+ +--------+ +-----+
"I guess steps 1) & 2) would require converting the ASCII characters to binary bits"
No - ASCII is just a way of encoding characters as "binary bits".
"the .txt files could be relatively large (e.g. 5 Mb) so I may not be able to store all the received data in memory"
Almost certainly not; but there but there would be no need or point - just "stream" the characters through.
You will probably need some sort of Flow Control
You will probably also want some sort of Error Detection
I would suggest that you look at protocols like XMODEM, YMODEM, etc, ...
"Is this something that is possible to do using uVision?"
Yes.
"how to read and write .txt files?"
You don't do that in the microcontrollers - that's on the PCs.
If you do mean that, then the 2 microcontrollers are, of course, redundant - you could just connect the 2 PCs together:
PC1 PC2 +-----+ +-----+ | | | | | Tx +------->+ Rx | | | | | +-----+ +-----+
But, presumably, that is not the point ... ?
Thanks for the inputs, Andrew.
You are correct that the link could be made simply by connecting the PCs together, but I actually want to transmit the data using an optical link - I didn't go into details as I'm pretty clear on what I want to do on the hardware side of things, and didn't want to over-complicate my original question.
I'm still not clear on how to go about getting information from a .TXT file to the Tx microcontroller (and doing the reverse at the Rx end). I think I have a decent grasp of how to transmit a block of data (thanks for clearing up ASCII coding, BTW), but no understanding of how to obtain that block from a .TXT file in the first place.
If you, or someone else, would be able to give a pointer on where to start there, that would be much appreciated.
You look to be tunneling a serial connection across several USART and a optical link. You'd need to manage the buffering, flow control, and integrity. You basically want to ensure the data you stuff in one end of the tunnel arrives unmolested at the other end. ie same data, same order, etc.
Familiarity with FILE IO using fopen/fread/fwrite/fseek/ftell/fclose? Data within the file is just collection of bytes, the OS doesn't care if they are ASCII, spreadsheets or executable code. On Windows boxes opening a COM port uses CreateFile, with data sent/received using WriteFile/ReadFile.
X-MODEM is frequently used for point-to-point transfer of files, sending ASCII data infers no size, and provides no integrity. The protocol provides a means of expressing a start and ending point, but does round the file size up to 128 or 1024 blocks. It is relatively simple to implement from scratch as it isn't that complicated. Y-MODEM provides file names and sizes.
Many Terminal applications implement it, and other protocols, for file transfers (think BBS from the 1990's).
As Westonsupermare Pier says, many (most?) terminal emulators can do this.
If you want an application on the PC to do it, then it's just standard PC file IO - nothing to do with microcontrollers or Keil.
Pretty sure that libraries are available to implement X/YMODEM for popular PC development tools ...
eg, if Python is your thing: pypi.python.org/.../xmodem