printf - MC68HC908BQ8

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

printf - MC68HC908BQ8

4,364 Views
Opal
Contributor I
Hi everyone,
 
I am using codewarrior IDE Version 5.9.0. And controller is MC68HC908BQ8.
I want to print the data of a global variable, I have included stdio.h and compiled
the compiler error I got was

"Symbol TERMIO_PutChar in file C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\lib\ansii.lib is undefined"

So I have included termio.c file and terminal.c  the program get comiled but I got run time error at location 

Error: At location 0203 -
Error: Attempt to use invalid or uninitialized memory

I got this error when I tried to execute the line in Bold

"if TEST_TERM
    while (!(SCI.SCSR & 0x80)) {};    /* wait for output buffer empty */
    SCI.SCDR = ch;"

This code is termio.c file


                   

And I got this code from the forum and tried to compile
#include <hidef.h>
#include <stdio.h>
#include <termio.h>
char buf[20];
int bufpos;
void TERMIO_Init(void) {
}
void TERMIO_PutChar(char ch) {
buf[bufpos]= ch;
bufpos++;
if (bufpos >= sizeof(buf)) {
bufpos -= sizeof(buf);
}
}
int dtTarget= 2;
void main(void) {
(void)printf("SP %u\n\r", dtTarget );
while (1) { _FEED_COP(); }
 
I got error as "Link Error   : L1102: Out of allocation space in segment RAM at address 0x11E".
Can someone provide the piece of code to print.
Labels (1)
Tags (1)
0 Kudos
6 Replies

621 Views
Opal
Contributor I
Thanks to everyone
Is that possible to write my own printf if so can someone guide me
0 Kudos

621 Views
bigmac
Specialist III
Hello,
 
To send the value of a global variable, via the SCI module, will require the following steps -
  1. Convert the variable value to an ASCII string sequence (null terminated), placed within an array variable.  The following thread may provide some ideas on how to do this -
    http://forums.freescale.com/freescale/board/message?board.id=CWCOMM&thread.id=5423
  2. Send the contents of the array variable, character by character, to the SCI module.  The TERMIO_PutChar() function within the file termio.c may be used for this purpose.
byte ascbuf[20];  // Global array variable for string data
 
void send_str(void)
{
   byte i = 0;
 
   while (ascbuf[i] > 0)
      TERMIO_SendChar(ascbuf[i++]);
}
The reason your previous attempt to use TERMIO_SendChar() failed is that you probably did not call TERMIO_Init() (also within termio.c file), prior to calling TERMIO_SendChar() for the first time.
 
Your own sample code for TERMIO_SendChar() is problematic because it seems to assume that SCI communications will be interrupt driven, and therefore fills a circular buffer with the character data.  However, this would also require ISR code for the SCI, to be able to send the data, and empty the buffer.
 
The code within termio.c does not use interrupts, so will tie up further code execution while the string data is sent.
 
Regards,
Mac
 


Message Edited by bigmac on 2007-11-23 01:49 PM
0 Kudos

621 Views
Opal
Contributor I
Hello,
 
I want to send/communicate through SPI.
 
1.Can I Use printf to send data through SPI?
2.I have used the following code to transmit data through SPI.
     I have used stimulation to check whether the data is coming correct.
     When I send integer value The output is coming correctly in SPI Module --->View SPI data. But when tried to send this as char (ie)  I have converted hex to dec and to ASCII value then from third data an 0x80 is getting added only in the display but the data is send through register is correct I have checked this through the statement na[i]=*(data+i); 
 I dont able to understand , why is it happening so?
 Whether what am I doing in the program is correct?
    
Code:
#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#include <string.h>void sendSPI(char *,int);void delay1s(void);void main(void) {int y,rec_data,len;                   //y,rec_data,,lenchar name[8]="Vowelopal"; OSCSC = 0x20;       // Set bus speed to 12.8 MHZ  OSCTRIM = Optional; // this macro loads value at $FFC0 and store it in $0038.                // bus clock speed is 3.2MHz +- 5%  CONFIG1 = 0x01;     // disable the watch dog.    SPSCR = 0x03;                                    SPCR_SPE = 1;  SPCR_SPMSTR = 1;  SPCR_CPHA = 1;  len=strlen(name) ; while(1) {   sendSPI(name,len);  SPDR = 0xAA;    while(!SPSCR_SPRF);    delay1s();  y = SPSCR;  rec_data = SPDR;     }  }  void sendSPI(char *data,int le) {   char i = 0;  int rec_data;   for(i=0; i<(le-1); i++)     {      SPDR = *(data+i);      //na[i]=*(data+i);            while(!SPSCR_SPRF);          SPSCR = SPSCR;      rec_data = SPDR;      delay1s(); }   }void delay1s(void) {   unsigned int i;  int j;   for(j=0;j<10;j++)    {     for (i = 0; i <= 20899;i++);          // Delay of 100mS   }                                       // 15 cycles per delay value                                // 6 uS for a 2.5 MHz clock                                          // 6 uS * 167000 = 1000 mS = 1 sec }

 
0 Kudos

621 Views
CompilerGuru
NXP Employee
NXP Employee
 First, printf is rather resource demanding, so I'm wondering if you might not be better using some more light weight way of printing to the SCI.
And second, the "TEST_TERM" part of termio.c wont work for a HC08 in the
debugger, neither on real hardware nor in the simulator :smileysad:.
Sorry, I dont know the details about the BQ8 device to help more, if it has a SCI module, it should not be hard to implement the two functions needed (TERMIO_PutChar, and the SCI has to be initialized too, an empty TERMIO_Init wont do that....).

Daniel



Message Edited by CompilerGuru on 2007-11-21 10:46 PM
0 Kudos

621 Views
bigmac
Specialist III
Hello,
 
I wonder if the OP actually means 908QB8, rather than 908BQ8?  If so, there are only 256 bytes of RAM available, and potential resource limit problems are compounded by the default PRM file, which confines both the globals and stack to page-1 RAM (64 bytes).  The PRM file will probably need to be altered, whether or not printf is utilized.
 
I agree that this particular device does not have sufficient resources to handle printf or sprintf.
 
Regards,
Mac
 
0 Kudos

621 Views
peg
Senior Contributor IV
Hello and welcome Opal,

In the first instance, as SCSR is being read, modify, written. CW does not like to read from locations that have not previously been written too. Just initialise this variable (even if you are just writing the POR value, before you get to this point in the programme.
In the second it appears you have run out of RAM, or at least the amount you have allocated here.

0 Kudos