Prinf() doesn't work

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

Prinf() doesn't work

2,381 Views
M3H0
Contributor I
Hi,
 
I wrote a message yesterday related with serial communication using MC9S12C32. I have been working quite tought with this, but I haven't succeed, here is my code, can anyone tell what is what I'm doing wrong?  what it doesn't work is the printf () sentence all the rest works. I'm using Imagecraft's ICC12 compiler+chips12 demoboard.
 
PD: ledon(), ledoff() & delay_ms() functions defined in the ofunc.h file
 

//Include files
#include <mc9s12c32.h>
#include "ofunc.h"
#include <stdio.h>

//MACROS DEFINITIONS
#define ENABLE_INTERRUPTS asm("cli")

//Definition of variables
short start=1, on=0;
char mensaje[]="hello world\n";


//Definition of functions
void SCItx(unsigned char SCIByte){
      SCIDRL = SCIByte;
/*Write data byte to SCIDRL register*/
       SCICR2 |= 0x80;
/*Enable TDRE interrupt*/
}

//Definition of interrupt service routines
#pragma interrupt_handler SCIhdr
extern void SCIhdr();
void SCIhdr(void){

//--------------------------Byte Transmision-------------------------------
       if (SCISR1 & 0x80){
               SCISR1;
               SCICR2&=0x7F;
      }
//if (SCISR1 & 0x80)
//-----------------------End of Byte Transmision---------------------------

//--------------------------Byte Reception---------------------------------
       if (SCISR1 & 0x20){
//Received data available in SCI data register
                SCISR1;
//Reading of SCISR1 needed to clear RDRF
                if(SCIDRL=='0'){
                       ledoff(2);
                       ledon(3);
                       SCItx('\n');
               }
               if (SCIDRL=='1'){
                       ledoff(3);
                       ledon(2);
               }
      }
//if (SCISR1 & 0x20)
//-----------------------End of Byte Reception-----------------------------
return;
}


//======================= Program´s main body ==================================
main(){

//SCI module configuration
SCIBDH=0x00; SCIBDL=0x1A;
//Baud rate=19.200
SCICR1=0x00;
//8 data bits & no parity
SCICR2 = 0xAC;
//Enable Tx, Rx, and RDRF interrupt
SCISR1;
//Port AD pins set as general porpouse outputs
DDRAD=0xFF;
//Switch on the led connected to PAD4 (LED2)
ledon(2);

//Enable interrupts
ENABLE_INTERRUPTS;
 
    while (1){
        if (start==1){
             SCItx('p');
             printf("Hola\r\n");
             start=0;
        }
        if (on==0){
             ledon(1);
             on=1;
        }
        else {
             ledoff(1);
             on=0;
             SCItx('A');
         }
        delay_ms(500);
    }
//While(1)
}
//main

 

THANK YOU VERY MUCH IN ADVANCE

Oroitz

Labels (1)
0 Kudos
5 Replies

608 Views
pittbull
Contributor III
Hello,

I think you should overwrite the 'putchar' function in order to make 'printf' work.
Please see the ICC manual how this can be done.

Cheers
-> pittbull
0 Kudos

608 Views
M3H0
Contributor I
Thank you for your reply,
 
Now I have another question, I have looked for the manual you have told me and I can't find it. Where it is located, in the help topics? or it is a different document? If it's a different document could you give me a URL from where I could download it, or could you attach it in the forum??
 
Best regards,
 
Oroitz
 
 
0 Kudos

608 Views
pittbull
Contributor III
Hi,

go to this site: http://www.dragonsgate.net/cgi-bin/FAQ/fom?_recurse=1&file=1
and search for "printf/puts"
0 Kudos

608 Views
M3H0
Contributor I
I have done what you have told me, but it doesn't works, this my new Putchar.c file's content:
 

#include <stdio.h>
#define _SCI
/* #include <hcs12dp256.h for S12DP256 */
#include <mc9s12c32.h>
#define TDRE 0x80

extern int _textmode;

int putchar(char c){
     if (_textmode && c == '\n')
             putchar('\r');
     while ((SCISR1 & TDRE) == 0)
         ;
     SCIDRL = c;
     return c;
}

I'm becoming mad, do you have some operating programs in which the serial communication works? could you attach it here?

Best regards

Oroitz

0 Kudos

608 Views
pittbull
Contributor III
Hi
Here is my old 'putchar' function for ICC12.

#pragma nonpaged_function putchar
int putchar(char c)
{
while((SCI0SR1 & 0x80) == 0) { } // loop until TDRE set // 0x08
SCI0DRL = c;
return c;
}

If that doesn't work for you, try in-memory formatting to get a printf-like function:

void my_printf (const char *format, ...)
{
static char outbuf[256];
char *p;
int i;

va_list args;
va_start(args, format);
i = vsprintf(outbuf, format, args);
va_end(args);

p = outbuf;
while (*p)
{
if (*p == '\n')
{
SIO_Write (0x0d);
SIO_Write (0x0a);
}
else
SIO_Write (*p);
p++;
}
}

The 'SIO_Write' is a function that sends single characters to RS232...
The 'my_printf' behaves similar to 'printf'
0 Kudos