8 years, 5 months ago.

How do I use serial write for uint8 buffer array?

I cannot compile if I use serial write(). It comes up with error: virtual ssize_t mbed::Stream::write(const void*, size_t)' is protected. Here is the function:

void serialWrite(Serial* _fd, uint8_t* buf, uint8_t len)
{
	int remain = len;
	int offset = 0;
	while (remain > 0)
	{
		int sub = (remain >= 8 ? 8 : remain);
		_fd->write(buf + offset, sub);
		wait(0.01);
		remain -= 8;
		offset += 8;
	}
	return;
}

The passed array like uint8_t cmd[] = { 0xAB, 0, 0xAC, 0xBC, 0xFE, 0x45, 0x68, 0xEA, 0x85, 0xBC, 0x62};

Develop env.: WIN7, Eclipse, Cross ARM GCC.

How do I fix it? Thanks.

Question relating to:

Rapid Prototyping for general microcontroller applications, Ethernet, USB and 32-bit ARM® Cortex™-M3 based designs

1 Answer

8 years, 5 months ago.

That is not the error I would have expected you would get, since as far as I am aware serial write function does not exist for the LPC1768. All those asynchronous functions are only available on a few Silicon Labs boards, and just polluting the documentation for all other platforms. One option you have is simply using putc on each byte you want to send in a loop.

If you do want to send it asynchronously you can have a look at either MODSERIAL of BufferedSerial libraries for your device.

Accepted Answer

Thanks for the answer. Yes, as your comment, I can go back to use printf by looping the size of array now.

posted by Patrick Shih 16 Oct 2015

use putc(char) rather than printf("%c",char), it's a lot faster.

posted by Andy A 16 Oct 2015