4

I have a Xilinx Virtex-II Pro FPGA board that is attached via RS232 to an iRobot Create.

The iRobot takes a stream of byte integers as commands.

I've found that printf will actually send over the serial port (Hypterminal is able to pick up whatever I print), and I figure that I can use printf to send my data to the iRobot.

The problem is that printf seems to format the data for ascii output, but I'd REALLY like it to simply send out the data raw.

I'd like something like:

printf(%x %x %x, 0x80, 0x88, 0x08);

But instead of the hexadecimal getting formatted, I'd like it to be the actual 0x80 value sent.

Any ideas?

2
  • Does your compiler support: printf(0x80,0x88,0x08);? Commented Dec 3, 2011 at 15:14
  • or printf("",0x80,0x88,0x08); Commented Dec 3, 2011 at 15:24

3 Answers 3

11

Use fwrite:

char buf[] = { 0x80, 0x80, 0x80 };

fwrite(buf, 1, sizeof(buf), stdout);

You can write to any file handle; stdout is just an example to mirror your printf.

On a Posix system, you can also use the platform-specific write function that writes to a file descriptor.

Sign up to request clarification or add additional context in comments.

5 Comments

This is good! But I don't know the address of my stdout,... I suppose I could try digging around. My idea is to just use the memory address of the RS232 RX output... Does that sound like the right idea?
Why do you need any address? You were happy to use printf earlier, and that's the same as fprintf(stdout, ...)... what's the question now? You most definitely can not write to any random number. It has to be a FILE* that you obtained legally somehow.
Huh... I've been using printf this whole time, but I don't seem to be able to include the stdio.h library, my compiler doesn't seem to like it... I.. am at a loss. Using stdout gives me an error, and including the library gives an error as well.
This seemed to be the answer in the end. I found I could use an equivalent in the platform I was using called STDOUT_BASE_ADDR. I didn't mark it right away because I finally figured out the cord I was using to connect the robot was bad T_T Took hours to figure it out. Thanks again Kerrek!
Nice. For long strings, this is much better than the "%c%c%c" format I've been using.
9

Use the format "%c%c%c" instead.

Comments

3

You would use fwrite instead. Printf is by definition an ascii printer.

char buf[] = {0x80, 0x80, 0x80};
fwrite(buf, 1, 3, stdout);

seems to be what you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.