2015-07-01 03:14 AM
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.
Solved! Go to Solution.
2015-07-07 02:59 AM
Ok, I solved so:
chprintf((BaseSequentialStream *)&SD1, ''Value of dur is: %d'', dur);
There was no cast.
Thanks.
Best regards
Gianluca.
2015-07-02 12:59 AM
Hello Gianluca ,
did you use Os-Less or Chibios ? if you use Chibios, chprintf should work ;) if you use Os-Less, you can integrate in your source application direction (the source file attached) Best Regards Erwan ________________ Attachments : serial_input.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0W4&d=%2Fa%2F0X0000000bZr%2FH5yg00pS62w672iu1wLqKRdMaTi8dQdIaF2G.iw2c.8&asPdf=falseserial_input.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0R5&d=%2Fa%2F0X0000000bZt%2FxUIfqW3LWVX.n3egUvLjb1dKtG1x_jFvdDuHC5MsyDk&asPdf=falseserialprintf.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Vz&d=%2Fa%2F0X0000000bZu%2FWqGV9yYfT6umnZ3GvrPEc2kDt9cj0.IWazKEz7QwOJA&asPdf=falseserialprintf.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Vp&d=%2Fa%2F0X0000000bZp%2Fe5KOCkwkxwq_c5lesj4PwB6y7V7xKt7tC8.96Avg7rs&asPdf=false2015-07-07 02:41 AM
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.
2015-07-07 02:59 AM
Ok, I solved so:
chprintf((BaseSequentialStream *)&SD1, ''Value of dur is: %d'', dur);
There was no cast.
Thanks.
Best regards
Gianluca.