2010-01-14 07:34 PM
Sending characters out of the simulator
2011-05-17 06:07 AM
Hi everyone:
I have a few questions about STM8. I am using the Cosmic compiler within STVD and trying to use the simulator that comes with the IDE. I am able to run some simple programs, however what I would like to do is to export characters out of the simulator to the host. I pursued a few avenues so far. One avenue was to use printf to print to the console. The following is the code I used... #include ''stdio.h'' #include ''iostm8a.h'' #define TRDE 0x80 /* transmit ready bit */ #define rim() _asm(''rim'') /* PUT A CHARACTER TO OUTPUT * Copyright (c) 1998 by COSMIC Software */ /* output a character */ char putchar(char c) { char VCAST_OUTCH = c; if (c == '\n') { /* put '\r' to hardware here */ while (!(USART_SR & TRDE)); /* wait for READY */ USART_DR = '\r'; /* send it */ } /* put c to hardware here */ while (!(USART_SR & TRDE)); /* wait for READY */ USART_DR = '\r'; /* send it */ return (c); } main() { USART_BRR1 = 0xc9; /* parameter for baud rate */ USART_CR1 = 0x00; /* parameter for word length */ USART_CR2 = 0x2c; /* parameters for interrupt */ rim(); /* authorize interrupts */ printf(''hello world''); printf(''hi again!''); } I might not have a complete code since I don`t know how to send these characters to the console. If this is the case, could someone kindly let me know? Researching on this forum, I also realized that in the release note, ST reports that the STM8 simulator does not implement peripherals, so on the other hand, there might not be any way to get to that console window. So, I tried to store characters sent to putchar to a file to be saved on the host through the debugger (gdb). My idea is to do something similar to this: fopen number myfile.txt watch putchar():char_being_written { operation to put the char in the file } go fclose file_number I tried to do fopen 1 out.txt, but GDB just reported `''fopen error'' without much details. I am also unsure of the operation to access to write the char values to file - in other environments, you can apparently do fwrite, but it does not seem to be the case here. Could someone give me a few pointers? Thanks!2011-05-17 06:07 AM
Hi,
The printf() function as it defined in the library stdio call the putchar() function to send data on the console, In your case you have personalized the putchar() function to send characters to the COM (HyperTerminal) To read data you need to personalize the getchar() function. You can refer to the USART_Printf example in the STM8S FWLibrary. Regards mozra