0

I am writting firmware for AT90CAN32 using AVR Studio + WinAVR. It seems simple for experienced AVR programmers. I pass int argument to function, but inside the function it is always zero. There is inside protocol.c file:

#include <uart.h>

static char packet[16] =  ":AA111122223!f\r\n";

void vDivRequesting(void)
{
    uint8_t cntOfBms = getCountOfBms( );
    for(uint8_t i=0; i<cntOfBms; i++)
    {
        createPacket(getBmsNetworkNumber(i), REQUEST_V_DIV, 1);
        usartSendString(packet,11);
        _delay_ms(200);
    }
}

There is uart.c file:

void usartSendString( char *data, uint8_t len )
{
    uint8_t i=0;
    usartSendByte(len + 0x30);
    for( i=0; i<len; i++)
    {
       usartSendByte(*data);
       *data++;
    }
}

And it prints me that len argument is zero. usartSendString function is defined in uart.h file. What is wrong with that code?

user3583807
  • 766
  • 1
  • 8
  • 26
  • How did you test `len` and get zero? Is it using i/o lines or after sending it to UART, Please add `usartSendByte` code for more clarrification – Nasr Sep 18 '15 at 18:23
  • The `0x30` offset only makes sense with values from 0-9 because `0x30` is the ASCII code for `0` and 0x39 for `9`. You use 11 as an argument for len, thus get `0x3B` which represents `;`. I don't know why it could be "zero" but you obviously should take a closer look at that. If `usartSendByte` works for you in general, you may want to juts send a letter or something in the for-loop to count the iterations. – Rev Sep 21 '15 at 06:06

0 Answers0