OWOWOD – One Wire / One Way Output for Debugging the Tinusaur (Part 2)

In my previous post “OWOWOD – One Wire / One Way Output for Debugging the Tinusaur (Part 1)” I wrote how to get a proper reference signal from a serial communication using USB-to-Serial TTL converter.

The Tinusaur BoardThe next steps are to generate the same signal but programmatically using the ATtiny85.

And this is what I did …

I used a ATtiny85 board, the Tinusaur – as you may have guessed already, connected with USBasp programmer to the computer.

The PB0 is used as output but any other available port could be used. That could be done by changing the OWOWOD_PORT in the source code below.

The output is connected to the second digital channel of my DSO Quad oscilloscope.

Here is a fragment of the code that generates the output sugnal …

#define OWOWOD_PORT	PB0	// OWOWOD Port

inline void owowod_init(void) {
	DDRB |= (1 << OWOWOD_PORT);	// Set port as output
	PORTB |= (1 << OWOWOD_PORT);	// Set to HIGH
}

#define OWOWOD_DELAY	23	// Delay for each bit

inline void owowod_delay(void) {
	for (uint8_t i = OWOWOD_DELAY; i != 0; i--) {
		asm volatile ("nop\n\t");
	}
}

void owowod_print_char(uint8_t c) {
	PORTB &= ~(1 << OWOWOD_PORT);	// Set to LOW
	owowod_delay();
	for (uint8_t i = 0; i < 8; i++)
	{
		if (c & 1) {
			PORTB |= (1 << OWOWOD_PORT);	// Set to HIGH
		} else {
			PORTB &= ~(1 << OWOWOD_PORT);	// Set to LOW
		}
		owowod_delay();
		c = (c >> 1);
	}
	PORTB |= (1 << OWOWOD_PORT);	// Set to HIGH
	owowod_delay();
}

int main(void)
{
	owowod_init();
	while (1) {
		owowod_print_char(0x55); // "U"
	}
	return (0);
}

The owowod_init() function sets the port as output and its level to high which is the default for the serial communication.

The owowod_delay() function is a custom delay function that should produce a delay that is equivalent of 1 bit of serial data. This is just an empty loop that I experimentally determined how long it should be.

The owowod_print_char(uint8_t) function outputs one byte of data in serial – starting from the least significant bit of that byte.

To run the test I first started the COMStressTest program and let it output the “U” character (ASCII code in HEX 0x55) indefinitely.

IMPORTANT: All the tests were done with the default settings for the serial COM port which are 9600 bps, 8 bits of data, no parity check and 1 stop bit. This is sometimes denoted as 9600 / 8-N-1 configuration.

Then I ran the C program on the ATtiny.

The graphic on the oscilloscope looked like this …

Serial Debugging Oscilloscope

To get the two signals the same took of course some time to figure out what the timings (the delay between bits) should be.

I am now another step farther.

The next step will be to write a simple debugging library for printing strings and numbers.

PREVIOUS PART: OWOWOD – One Wire / One Way Output for Debugging the Tinusaur (Part 1)

NEXT PART: OWOWOD – One Wire / One Way Output for Debugging the Tinusaur (Part 3)

 

All the OWOWOD source code is available at https://bitbucket.org/tinusaur/owowod/src.

 

Advertisements

3 thoughts on “OWOWOD – One Wire / One Way Output for Debugging the Tinusaur (Part 2)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s