cancel
Showing results for 
Search instead for 
Did you mean: 

[Solved] How can I print an Integer

gl2
Associate III
Posted on July 01, 2015 at 12:14

Hello.

I use the board SPC560P-DISP. How can I print an Integer with Tera Term through a serial connection? I use the function chnWriteTimeout to print a string. So:

chnWriteTimeout(&SD1, (uint8_t *)
''Hello World!\r\n''
, 14, TIME_INFINITE);

But an Integer? I tried to use chprintf, but not working. It does not recognize the function chprintf. I included the header chprintf.h

uint32_t number=25;
chprintf(&SD1, 
''%u \n\r''
, number);

The error is:

main.c:(.text_vle.main+0x10c): undefined reference to `chprintf'
collect2: ld returned 1 exit status
make: *** [build/
out
.elf] Error 1

In the demo of SPC5 Studio for my board they use only chnWriteTimeout. Best regards Gianluca.
This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
gl2
Associate III
Posted on July 07, 2015 at 11:59

Ok, I solved so:

chprintf((BaseSequentialStream *)&SD1, ''Value of dur is: %d'', dur);

There was no cast. Thanks. Best regards Gianluca.

View solution in original post

3 REPLIES 3
gl2
Associate III
Posted on July 07, 2015 at 11:41

Hello,

I use this code, but nothing happens. I enabled the serial connection and set the baud to 38400 of Tera Term. When I try to use chprintf nothing appears on the screen.

/*
ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the ''License'');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an ''AS IS'' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* Inclusion of the main header files of all the imported components in the
order specified in the application wizard. The file is generated
automatically.*/
#include ''components.h''
#include ''shellcmd.h''
/*
* Shell configuration structure, the first field is the serial port used by
* the shell, the second is the array of commands accepted by the shell and
* defined in shellcmd.c.
*/
static
const
ShellConfig shell_cfg1 = {(BaseSequentialStream *)&SD1,
shell_commands};
/*
* LEDs blinker thread, times are in milliseconds.
*/
static
WORKING_AREA(waThread1, 128);
static
msg_t Thread1(
void
*arg) {
(
void
)arg;
chRegSetThreadName(
''blinker''
);
while
(TRUE) {
//uint32_t duration=3, distanceCm;
unsigned 
int
dur=3;
palClearPad(PORT_A, TRIG_PIN); 
// low
osalThreadSleepMicroseconds(2);
palSetPad(PORT_A, TRIG_PIN); 
//high
osalThreadSleepMicroseconds(10);
palClearPad(PORT_A, TRIG_PIN); 
// low
palTogglePad(PORT_A,Led_D12);
//chnWriteTimeout(&SD1, (uint8_t *)''%u

'', 14, TIME_INFINITE);
chprintf(
''%u''
, dur);
osalThreadSleepMilliseconds(500);
}
return
0;
}
/*
* Application entry point.
*/
int
main(
void
) {
//Thread *shelltp = NULL;
/* Initialization of all the imported components in the order specified in
the application wizard. The function is generated automatically.*/
componentsInit();
/*
* Activates the serial driver 1 using the driver default configuration.
*/
sdStart(&SD1, NULL);
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, 
sizeof
(waThread1), NORMALPRIO, Thread1, NULL);
/* Application main loop.*/
// while (1) {
// if (!shelltp)
// shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
//else if (chThdTerminated(shelltp)) {
//chThdRelease(shelltp); /* Recovers memory of the previous shell. */
//shelltp = NULL; /* Triggers spawning of a new shell. */
//}
chThdSleepMilliseconds(1000);
//}
}

Why? Best regards Gianluca.
gl2
Associate III
Posted on July 07, 2015 at 11:59

Ok, I solved so:

chprintf((BaseSequentialStream *)&SD1, ''Value of dur is: %d'', dur);

There was no cast. Thanks. Best regards Gianluca.