[SOLVED] (Yet another) 74HC165 read problem

Go To Last Post
38 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys

 

apologies, I know this is almost a FAQ but I am struggling to read serial data from a '165 connected to an ATMega168.

I am trying to read the status of 10 pushbuttons, so I am using two cascaded '165, 8 buttons on the first, two on the second. Second '165 has the unused parallel inputs grounded. No floating pins anywhere.

QH of the second connected to the SER of the first. Both '165 share CLK, CLK INH and LD.

 

Each parallel input has a pullup resistor, so buttons connect to ground.

Hence, if nothing happens, I should read 10 1's and 6 0's.

I read 0x04 from both '165!!!

No button press is detected (I am not deboucing, I just keep the button pressed for seconds)

 

Connections are good, checked them like ten times. I'll check them again tomorrow. I will slow down the code and look what happens on the scope.

 

My code is really simple, but I'd like an extra pair of eyes to help me now, as I am banging my head against the wall.

I thought it would have been a piece of cake (I am using a MAX7219 and other stuff in the same project and I had to make much more complicated things...)

 

Any other tips/suggestions?

Thanks

 

#define QH_PIN		PIND4
#define QH_PORT		PORTD4
#define CLKINH_PORT	PORTD5
#define CLK_PORT	PORTD6
#define LD_PORT		PORTD7

#define SET_HC165_DDR	(DDRD |= (1 << CLKINH_PORT) | (1 << CLK_PORT) | (1 << LD_PORT))
#define SET_QH_PULLUP	(PORTD |= (1 << QH_PORT))
#define CLKINH_HIGH (PORTD |= (1 << CLKINH_PORT))
#define CLKINH_LOW 	(PORTD &= ~(1 << CLKINH_PORT))
#define CLK_HIGH 	(PORTD |= (1 << CLK_PORT))
#define CLK_LOW		(PORTD &= ~(1 << CLK_PORT))
#define LD_HIGH		(PORTD |= (1 << LD_PORT))
#define LD_LOW		(PORTD &= ~(1 << LD_PORT))

/*
 * Read serial data.
 * Bytes are stored into the serial_data array.
 */
void HC165_readSerialData(uint8_t serial_data[])
{
	uint8_t i,j;
	uint8_t _byte;

	/* Pulse LD low and then high to load parallel data */
    LD_LOW;
    LD_HIGH;

	/* Set CLK INH low to allow clocking */
    CLKINH_LOW;

    /* For each '165... */
	for (i = 0; i < 2; i++) {
		_byte = 0;
		/* ...read the serial out data */
		for (j = 0; j < 8; j++) {
			_byte <<= j;
			_byte |= QH_PIN;
			CLK_LOW;
			CLK_HIGH;
		}
		serial_data[i] = _byte;
	}

	/* Disable clocking now */
	CLKINH_HIGH;
}

int main()
{
    SET_HC165_DDR;
    SET_QH_PULLUP;

    uint8_t buttons[2] = {0, 0};

    for (;;) {

		HC165_readSerialData(buttons);
		_delay_ms(20);

	}

    return 0;

}

 

 

This topic has a solution.
Last Edited: Sat. Mar 11, 2017 - 07:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
	<SNIP>
		for (j = 0; j < 8; j++) {
			_byte <<= j;
			_byte |= QH_PIN;
	<SNIP>

On your last pass you shift away most of your bits with <<= 7. You then grab a constant of 0x04.

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
#define QH_PIN		PIND4
#define QH_PORT		PORTD4
#define CLKINH_PORT	PORTD5
#define CLK_PORT	PORTD6
#define LD_PORT		PORTD7

#define SET_HC165_DDR	(DDRD |= (1 << CLKINH_PORT) | (1 << CLK_PORT) | (1 << LD_PORT))
#define SET_QH_PULLUP	(PORTD |= (1 << QH_PORT))
#define CLKINH_HIGH (PORTD |= (1 << CLKINH_PORT))
#define CLKINH_LOW 	(PORTD &= ~(1 << CLKINH_PORT))
#define CLK_HIGH 	(PORTD |= (1 << CLK_PORT))
#define CLK_LOW		(PORTD &= ~(1 << CLK_PORT))
#define LD_HIGH		(PORTD |= (1 << LD_PORT))
#define LD_LOW		(PORTD &= ~(1 << LD_PORT))

/*
 * Read serial data.
 * Bytes are stored into the serial_data array. 
 */
void HC165_readSerialData(uint8_t serial_data[])
{
	uint8_t i,j;
	uint8_t _byte;
	
	/* Pulse LD low and then high to load parallel data */
    LD_LOW;
    LD_HIGH;

	/* Set CLK INH low to allow clocking */
    CLKINH_LOW;
    
    /* For each '165... */
	for (i = 0; i < 2; i++) {
		_byte = 0;
		/* ...read the serial out data */
		for (j = 0; j < 8; j++) {
			_byte <<= 1;    //shifts a reasonably expensive,so we only do one shift per loop
			if (PIND & (1<<QH_PIN)
			    {
			        _byte |=1;  //then we conditionally set the lsb
			    }
			CLK_LOW;
			CLK_HIGH;
		}
		serial_data[i] = _byte;
	}

	/* Disable clocking now */
	CLKINH_HIGH;    //got me beat why you need to inhibit the clock - I'd just tie it low and save a port pin
}


int main() 
{
    SET_HC165_DDR;
    SET_QH_PULLUP;
    
    uint8_t buttons[2] = {0, 0};
    
    for (;;) {
	
		HC165_readSerialData(buttons);
		_delay_ms(20);

	}
   
    return 0;
    
}

This should hopefully work a bit better - I've not tested it. There's two basic techniques you can use when shifting in bits - either form a mask like you did, but this needs a variable amount of shifts. If it were an ARM processor, it wouldn't be an issue as the ARM cortex can do a variable amount of shifts in one clock, the AVR needs multiple. Or as I've done it, shift the variable then conditionally OR in the next '1' bit.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

This should hopefully work a bit better - I've not tested it.

 

I tested it for you and it works :)

 

Stupid me.

First, I indeed meant to type _byte <<= 1 NOT _byte <<= j. Working at night, and almost in the dark to keep the family sleeping, doesn't help...

Second, how could I think to test the PIN value that way? Doh!

 

Two facepalms in a row. I won.

 

Thanks folks.

Stefano

Last Edited: Sat. Mar 11, 2017 - 12:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:


void HC165_readSerialData(uint8_t serial_data[])
{
	uint8_t i,j;
	uint8_t _byte;
	
	/* Pulse LD low and then high to load parallel data */
    LD_LOW;
    LD_HIGH;

	/* Set CLK INH low to allow clocking */
    CLKINH_LOW;
    
    /* For each '165... */
	for (i = 0; i < 2; i++) {
		_byte = 0;
		/* ...read the serial out data */
		for (j = 0; j < 8; j++) {
			_byte <<= 1;    //shifts a reasonably expensive,so we only do one shift per loop
			if (PIND & (1<<QH_PIN)
			    {
			        _byte |=1;  //then we conditionally set the lsb
			    }
			CLK_LOW;
			CLK_HIGH;
		}
		serial_data[i] = _byte;
	}

	/* Disable clocking now */
	CLKINH_HIGH;    //got me beat why you need to inhibit the clock - I'd just tie it low and save a port pin
}


    uint8_t buttons[2] = {0, 0};
    
    for (;;) {
	
		HC165_readSerialData(buttons);
		_delay_ms(20);

	}
   
    return 0;
    
}

 

Sorry I am a bit confused ! the 16 bit or 2 byte is "_byte" or "buttons"?if I want to out put this two byte which should I use?

 while(1)
    {     
        
       uint8_t buttons[2] = {0, 0};
    
    for (;;)
     {
		HC165_readSerialData(buttons);
		delay_ms(20);
      } 
       PUSH595Write(_byte);//this is to out put what I get out of serial out put.
         delay_ms(1000);
     } 

This is what I have written in my code in which I expect 16 leds to respond.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To do 16 bits the destination would be uint16_t not uint8_t  and the for() loop limit would be 16 not 8.

 

(but let's keep this to one thread - you were already asking about this in another thread)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

_byte is a local variable in the HC165_readSerialData function. It doesn't exist outside that function. That function is passed a pointer to an array of uint8_t. The way that function is called means the two byte result is in the buttons array.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

To do 16 bits the destination would be uint16_t not uint8_t  and the for() loop limit would be 16 not 8.

 

(but let's keep this to one thread - you were already asking about this in another thread)

Sorry I am new to this don;t know how to manage the questions and comments,thats why you see me wondering around!

How do i start a new topic or question?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
_byte is a local variable in the HC165_readSerialData function. It doesn't exist outside that function. That function is passed a pointer to an array of uint8_t. The way that function is called means the two byte result is in the buttons array.

I am not that sharp to understand your point .Seeing my code ,how can I change it to read what I get from serial out put?What does this mean"for(;;)"?

Last Edited: Tue. Mar 14, 2017 - 01:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

azizollah wrote:
What does this mean"for(;;)"?

What does your C textbook say that for() means, and what the parameters are?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am waiting for Kartman to help.I have used your code but there seem to be a small mistake in my manipulation.

This is my code :


void PUSH595Write(uint8_t _byte)
   { 
    // uint8_t _byte;
     int i=0;
     for(i=0;i<8;i++)
       {
         if(_byte & 0b10000000)
           {
            HC595DataHigh();
           }
       else
           {
            HC595DataLow();           
           }
       PUSH595Pulse();  //Pulse the Clock line
       delay_us(10);
       _byte=_byte<<1;  //Now bring next bit at MSB position
       }
    PUSH595Latch();
   }  



 while(1)
    {     
       
       
    
    //for (;;)
    // {
		HC165_readSerialData(buttons);
		delay_ms(20);
    //  } 
       PUSH595Write(buttons[2]);
       
       
     }

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's pretty difficult to follow your code. Looking at it, it should not even compile as you use variables that are either commented out (like _byte) or not declared (like buttons).

So what you want to do is to read the status of 8 pushbuttons connected to a '165 and send the same status to a '595 right?

 

The function that reads 8 bits from the '165 is this one:

 

void HC165_readSerialData(uint8_t *serial_data)
{
	uint8_t j;
	uint8_t _byte;
	
	/* Pulse LD low and then high to load parallel data */
    LD_LOW;
    LD_HIGH;

	/* Set CLK INH low to allow clocking */
    CLKINH_LOW;
    
	_byte = 0;
	for (j = 0; j < 8; j++) {
        _byte <<= 1;
		if (PIND & (1<<QH_PIN)
		    _byte |=1;

		CLK_LOW;
		CLK_HIGH;
	}

	*serial_data = _byte;

	/* Disable clocking now */
	CLKINH_HIGH;    //got me beat why you need to inhibit the clock - I'd just tie it low and save a port pin
}

 

You can call it from the main loop as this:

 

uint8_t data;
while (1) {
    HC165_readSerialData(&data);
    
    processData(data);
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No. SPassig ,I don't think this is the write code.first of all the inputs are 16 bit or 2 bytes  and secondly this 2 byte must be sent back serially and receive it parallel.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I'm confused - what are we wanting to do? Read 16 bits from 165s or write 16 bits to 595s? Let's solve one problem first!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
I'm confused - what are we wanting to do? Read 16 bits from 165s or write 16 bits to 595s? Let's solve one problem first!

Well first is reading ,then writing. The reading part I used your code ,but it seems that I don;t get what I put to the inputs ,how do we check that?

I tried to write what I read back to the input to check if it runs ok ,but not sure about both procedure. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:
how do we check that?

I tried to write what I read back to the input to check if it runs ok ,but not sure about both procedure.

Clearly, your check needs to use a method that you know works - for sure!

 

This is a key reason why it's so often suggested that beginners should start by getting the UART to work:

 

http://www.avrfreaks.net/comment...

 

Then you can use the UART to output debug/diagnostic information like this.

 

Another key tool that you really should learn to use from the outset is the debugger - again, see the above link.

 

Further options include:

 

  • Write the received value to port pins;
  • Write the received value to the LCD, if you have one.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Remember: 165 is parallel-in-serial-out (PISO). 595 are serial-in-parallel-out (SIPO).

So you can't feed the 165 with a serial data, it won't work.

As well, you can't feed the 595 with parallel data.

 

Then, I am still confused how many bits you need to read and write. 8 or 16?

 

If you need to read 16 bits you need to have two 165.

Did you daisychained them the right way? Are you applying clock and parallel load signals to both of them?

Same for 595. They need to be daisychained, and signals need to go to both of them.

 

Start with one 165 and one 595. It's easier to debug. After you have that working, extending to 16 bits is pretty simple.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In fact I have the LCD and can send it to. I will try what you said.thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:

 

How do i start a new topic or question?

 

First click on Forums and select the best one for your question, for example in the "megaAVR and tinyAVR".

 

You will then be taken to the selected forum.

 

Then second click on the "Start a new Topic".

 

Please create a title for this topic that explains BRIEFLY what it is about. "Help me" is not a good title.

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

spassig wrote:

Remember: 165 is parallel-in-serial-out (PISO). 595 are serial-in-parallel-out (SIPO).

 daisychained them the right way? Are you applying clock and parallel load signals to both of them?

Same for 595. They need to be daisychained, and signals need to go to both of them.

 

Start with one 165 and one 595. It's easier to debug. After you have that working, extending to 16 bits is pretty simple.

Yes I have two 165 and two 595 rightly connected ,so bits are 16 not 8. But as Kartman suggested we should proceed byte by byte(8 bit at a time).So data is put in parallel and read serially ,then again sent back serially to get them in parallel.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

azizollah wrote:

 

How do i start a new topic or question?

 

 

First click on Forums and select the best one for your question, for example in the "megaAVR and tinyAVR".

 

You will then be taken to the selected forum.

 

Then second click on the "Start a new Topic".

 

Please create a title for this topic that explains BRIEFLY what it is about. "Help me" is not a good title.

 

 

Thanks Valusoft, you have been very helpful to me. 

Last Edited: Wed. Mar 15, 2017 - 08:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Kartman,

I checked input and output ,the result is : whatever the input ,the out put is always the same! don;t know which part is not correct.

Last Edited: Wed. Mar 15, 2017 - 07:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:
I have the LCD and can send it to.
Use the LCD to show what is being read from the 165. Once you have that debugged, start trying to output to the 595.

Trying to do both at the same time allows too many possibilities for error.

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:
don;t know which part is not correct.

Which is exactly why you do not try to debug them both at once!

 

Get one working & solid first;

 

Then get the other solid working;

 

Then - and only then - get them both working together.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK .I tested the outcome of 165 it works ok ,and this is the code how I tested it:

 void HC165_readSerialData(uint8_t serial_data[])
{
	uint8_t i,j;
	uint8_t _byte;
	
	/* Pulse LD low and then high to load parallel data */
    PORTC.3=0;//LD_LOW;
    delay_ms(100);
    PORTC.3=1;//LD_HIGH;

	/* Set CLK INH low to allow clocking */
    //CLKINH_LOW;
    
    /* For each '165... */
	for (i = 0; i <= 2; i++)
     {
		_byte = 0;
		/* ...read the serial out data */
		for (j = 0; j <= 8; j++) {
			_byte <<= 1;    //shifts a reasonably expensive,so we only do one shift per loop
			if (PIND.5 & (1<<QH_PIN))
			    {
			        _byte |=1;  //then we conditionally set the lsb 
                    
			    }
			PORTD.7=0;//CLKINH_LOW; 
            delay_ms(10);
			PORTD.7=1;//CLKINH_HIGH;
             if(PIND.5==0)
                      {
                      LCDprint("Zero");
                      delay_ms(100);
                      LCDcmd(0x01);
                      }
                  else if(PIND.5==1)
                      {                                                                                                                                                                                                  
                      LCDprint("One");
                      delay_ms(100);
                      LCDcmd(0x01); 
                      } 
		}
		serial_data[i] = _byte;
       LCDdata(_byte);
       delay_ms(1000);
	}

Now the problem is this : the bits are not making a byte ie (_byte) is not printed on LCD.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does LCDdata() actually do? Is it some kind of integer to ASCII conversion followed by output? Or does it just print the single character for the given 0..255 value? if the latter perhaps _byte contains a non-printable value?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

What does LCDdata() actually do? Is it some kind of integer to ASCII conversion followed by output? Or does it just print the single character for the given 0..255 value? if the latter perhaps _byte contains a non-printable value?

I think instruction do not exit the loop for(;;).

 

There are these kind of instructions for LCD:

1- LCDcmd(unsigned char cmd)

2- LCDdata(unsigned char data)

3- LCDprint(const char* str)

The _byte contains 0 and 1 and should be put in the form of 0x56 or something.

So how can I show the (_byte) on lcd?

 

Last Edited: Thu. Mar 16, 2017 - 10:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's your code - so you need to look into those functions and find out what they do!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azizollah wrote:
2- LCDdata(unsigned char data)
That does ont answer the question I asked. So if I were to use:

LCDdata('C');

would I expect to see a 'C' on the LCD?

 

If so then this is the WRONG routine to use to print the binary value that is in _byte.

 

Maybe try:

#include <stdlib.h>

...

char buffer[16];
itoa(_byte, buffer, 10);
LCDprint(buffer);

The itao() function will convert _byte into something "human readable" as a character string array and then this is passed to the character string printing function.

 

If, for example _byte contains 0xCE then in decimal this is 206 so the itoa() will convert 206 into the three characters "206" and then these will be printed on the LCD. For looking at binary patterns you may find it easier to display as binary or hex. In which case use either:

itoa(_byte, buffer, 2); // 2 = binary
itoa(_byte, buffer, 16); // 16 = hex

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

LCDdata('C');

would I expect to see a 'C' on the LCD?

 

If so then this is the WRONG routine to use to print the binary value that is in _byte.

 

Maybe try:

#include <stdlib.h>

...

char buffer[16];
itoa(_byte, buffer, 10);
LCDprint(buffer);

The itao() function will convert _byte into something "human readable" as a character string array and then this is passed to the character string printing function.

 

If, for example _byte contains 0xCE then in decimal this is 206 so the itoa() will convert 206 into the three characters "206" and then these will be printed on the LCD. For looking at binary patterns you may find it easier to display as binary or hex. In which case use either:

itoa(_byte, buffer, 2); // 2 = binary
itoa(_byte, buffer, 16); // 16 = hex

 

Thaks. But this is the message I get when I use either of these: 

 

itoa(_byte, buffer, 10);
itoa(_byte, buffer, 16);

itoa(_byte, buffer, 2);

 

Error:  too many arguments in function call

 

Last Edited: Sat. Mar 18, 2017 - 09:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you include stdlib.h?

How do you call it?

It's IMPOSSIBLE to help you if you just provide the error message and pieces of code without context.

 

First, though, you need to make sure you are using them correctly.

Read the manual page for the functions:

 

http://www.atmel.com/webdoc/avrl...

 

itoa expects a signed integer, a pointer to an allocated string where to host the conversion, and the base.

Is it what you are passing?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

spassig wrote:

Did you include stdlib.h?

 

Yes I included that in the program.

How do you call it?This is how I call it:

  void HC165_readSerialData(uint8_t serial_data[])
{
	uint8_t i,j;
	uint8_t _byte;
	 itoa(_byte, buffer, 2); // 2 = binary
   //  itoa(_byte, buffer, 16); // 16 = hex
	/* Pulse LD low and then high to load parallel data */
    PORTC.3=0;//LD_LOW;
    delay_ms(100);
    PORTC.3=1;//LD_HIGH;

	/* Set CLK INH low to allow clocking */
    //CLKINH_LOW;

    /* For each '165... */
	for (i = 0; i <= 2; i++)
     {
		_byte = 0;
		/* ...read the serial out data */
		for (j = 0; j <= 8; j++) {
			_byte <<= 1;    //shifts a reasonably expensive,so we only do one shift per loop
			if (PIND.5 & (1<<QH_PIN))
			    {
			        _byte |=1;  //then we conditionally set the lsb 

			    }
			PORTD.7=0;//CLKINH_LOW;
            delay_ms(10);
			PORTD.7=1;//CLKINH_HIGH;
             if(PIND.5==0)
                      {
                      //PUSH595Write(0);
                      LCDprint("0");
                      delay_ms(100);
                      //LCDcmd(0x01);
                      }
                  else if(PIND.5==1)
                      {
                       //PUSH595Write(1);
                      LCDprint("1");
                      delay_ms(100);
                      //LCDcmd(0x01);
                      }
		}
		serial_data[i] = _byte;

        LCDprint(buffer);

	}

It's IMPOSSIBLE to help you if you just provide the error message and pieces of code without context.

What code you need to see to say whats wrong and where?

First, though, you need to make sure you are using them correctly.

Read the manual page for the functions:

I read the manual ,but didn;t understand it!

 

 

itoa expects a signed integer, a pointer to an allocated string where to host the conversion, and the base.

Is it what you are passing?

I don;t know what you mean Sorry.

 

Last Edited: Sat. Mar 18, 2017 - 02:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You seem to be using Codevision as the compiler. Is this the case? If not, your code has even more problems.
You have not provided enough information - we can try to guess what you are doing, but there are limits to how much our crystal ball tells us.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
You seem to be using Codevision as the compiler. Is this the case? If not, your code has even more problems. You have not provided enough information - we can try to guess what you are doing, but there are limits to how much our crystal ball tells us.

Yes ofcourse my compiler is codevision.This I said from beging(or I thought I said!).

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may have mentioned it in another thread but not here. You were advised to start another thread - this might be one reason why. Tacking onto a thread that has code for avr-gcc also causes confusion.
As for atoi(), have you read the Codevision help? I'd suggest you go away and do some research. It might give us some time to recover from the annoyance you've caused.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The very first mention of the word "Codevision" in this thread is in post #33 in fact.

itoa() is not a standard C function so not all compilers provide it and those that do may implement it in different ways.

I'm used to the one in av-gcc. It takes THREE parameters where the third is "radix" which says what number base you want to use. The version of itoa() in Codevision does not offer this choice and only does decimal so it has two parameters. They are the same as the first two in my examples.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The itoa at the beginning of the beginning of the HC165_readSerialData function has no value for _byte to convert to ASCII in the buffer.

 

It appears you are passing serial_data to the HC165_readSerialData function, but then at the end trying to assign 2 elements of serial_data the bytes being shifted in from the165?

 

I am not familiar with codevision but I doubt the line if (PIND.5 & (1 << QH_PIN)) does what you think if QH_PIN is defined as PIND4 as in post #1.

 

It seems you are just putting fragments of code anywhere without regard to what each line is doing or trying to accomplish.

 

Edit: typo and wording change for clarity.

David (aka frog_jr)

Last Edited: Sat. Mar 18, 2017 - 03:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you all for your kind help.

I think I;d better go away and try to put my problem in a different way.