您好:
我在ti官方网站,看到ccsv4对printf的实现如下
add_device("uart", _SSA, uart_open, uart_close, uart_read, uart_write, uart_lseek, uart_unlink, uart_rename);
fopen("uart","w");
freopen("uart:", "w", stdout); // redirect stdout to uart
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout
printf("^_^\r\n");
但发现printf有时候带参数时,参数无法输出的现象。
谢谢
Forrest:
我试了一下,没能重复这个问题。
建议楼主把CCS升级到最新版本再试,楼主用的是哪款芯片,程序是怎么写的?
您好:
我在ti官方网站,看到ccsv4对printf的实现如下
add_device("uart", _SSA, uart_open, uart_close, uart_read, uart_write, uart_lseek, uart_unlink, uart_rename);
fopen("uart","w");
freopen("uart:", "w", stdout); // redirect stdout to uart
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout
printf("^_^\r\n");
但发现printf有时候带参数时,参数无法输出的现象。
谢谢
shen lee:
回复 Forrest:
感谢Forrest的回答, 下面是我的初始化函数
使用CCS4.2 和CCS4.12仿似都不行 芯片是F28335
void bsp_InitUart(void)
{
//the next 4 lines are from ti
add_device("uart", _SSA, uart_open, uart_close, uart_read, uart_write, uart_lseek, uart_unlink, uart_rename);
fopen("uart","w");
freopen("uart:", "w", stdout); // redirect stdout to uart
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout
printf("^_^\r\n");
}
int uart_open(const char *path, unsigned flags, int llv_fd)
{
uint16_t baudrate;
#ifdef SCI_PORT_A
InitSciaGpio();
#elif defined(SCI_PORT_B)
InitScibGpio();
#else
InitScicGpio();
#endif
ScibRegs.SCIFFTX.all=0xE040;
ScibRegs.SCIFFRX.all=0x204f;
ScibRegs.SCIFFCT.all=0x0;
SCI.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SCI.SCICTL1.all = 0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SCI.SCICTL2.bit.TXINTENA = 0;
SCI.SCICTL2.bit.RXBKINTENA = 0;
baudrate = SCI_PRD;
baudrate = (baudrate >> 8);
SCI.SCIHBAUD = baudrate; // 9600 baud @LSPCLK = 37.5MHz.
baudrate = SCI_PRD;
baudrate = (baudrate & 0x00FF);
SCI.SCILBAUD = baudrate;
SCI.SCIFFRX.all = 0x0001;
SCI.SCICTL1.all = 0x0023; // Relinquish SCI from Reset
SCI.SCIFFTX.bit.TXFIFOXRESET=1;
SCI.SCIFFRX.bit.RXFIFORESET=1;
}
int uart_close(int dev_fd){return ;}
int uart_read(int dev_fd, char *buf, unsigned count)
{
//while(count–)
{
while(SCI.SCIFFRX.bit.RXFFST == 0) { } // wait for XRDY =1 for empty state
// Get character
*buf++ = (char)SCI.SCIRXBUF.all;
}
return count;
}
int uart_write(int dev_fd, const char *buf, unsigned count)
{
//while(count–)
{
while (SCI.SCIFFTX.bit.TXFFST != 0) {}
SCI.SCITXBUF = *buf++;
}
return count;
}
off_t uart_lseek(int dev_fd, off_t offset, int origin){return ;}
int uart_unlink(const char *path){return ;}
int uart_rename(const char *old_name, const char *new_name){return ;}
谢谢
您好:
我在ti官方网站,看到ccsv4对printf的实现如下
add_device("uart", _SSA, uart_open, uart_close, uart_read, uart_write, uart_lseek, uart_unlink, uart_rename);
fopen("uart","w");
freopen("uart:", "w", stdout); // redirect stdout to uart
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout
printf("^_^\r\n");
但发现printf有时候带参数时,参数无法输出的现象。
谢谢
shen lee:
回复 shen lee:
补充:
printf("baudrate is %d\n",9600); 没问题
baudrate = 9600;
printf("baudrate is %d\n",baudrate); 不可以 正确输出baudrate is 9600
谢谢
您好:
我在ti官方网站,看到ccsv4对printf的实现如下
add_device("uart", _SSA, uart_open, uart_close, uart_read, uart_write, uart_lseek, uart_unlink, uart_rename);
fopen("uart","w");
freopen("uart:", "w", stdout); // redirect stdout to uart
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout
printf("^_^\r\n");
但发现printf有时候带参数时,参数无法输出的现象。
谢谢
shen lee:
回复 Forrest:
Forrest 你好,我的代码已贴出,能否给贴一下你的 给look一下,thanks
您好:
我在ti官方网站,看到ccsv4对printf的实现如下
add_device("uart", _SSA, uart_open, uart_close, uart_read, uart_write, uart_lseek, uart_unlink, uart_rename);
fopen("uart","w");
freopen("uart:", "w", stdout); // redirect stdout to uart
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout
printf("^_^\r\n");
但发现printf有时候带参数时,参数无法输出的现象。
谢谢
shen lee:
回复 Forrest:
你好,谢谢你的回答,呵呵,之前我对printf重定向时参考的就是这个文档,也许什么地方没注意到,我再仔细看看,实验一下把。谢谢