The steps that allow you to access each element of the array.
The steps that allow you to access each element of the array.
Where in the array do you want to start? At the beginning, I'm assuming. What is the first index of that array?
Where in the array do you want to end? At the end, I'm assuming. What is the last valid index of that array?
If you want to send two bytes before your delay, and repeat that process, how many indices are you moving through your array each time?
I feel
One more thing, __delay_us(5) should be given only at 2,4,6 bytes transfer. After 8 bytes delay is different as written.Code:for ( i = 0; i < 8; i+=2 ) { exchange8bit(union_data); __delay_us(5); } __delay_us(100);
Is it fine?
Is this more appropriate?
Code:uint8_t buf[8] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}; void get_data(uint8_t buf[]) { for ( i = 0; i < 8; i+=2 ) { exchange8bit(uint8_t data); __delay_us(5); //only after transferring 2-bytes. } // loop should transfer total 8 bytes. __delay_us(100); }
If "exchange8bit()" sends one byte, and you want to send two, then you're not quite there. Also, you're not calling that function correctly.
And if your function sends bytes, perhaps "send_data()" is a more appropriate name.
I would also recommend passing the size of the array to your function, instead of using the hard-coded value of 8.
I have modified as per suggestion
But still I feel there is issue which you pointed "If "exchange8bit()" sends one byte, and you want to send two, then you're not quite there." I have modified exchange8bit() as send_data. Yes it sends 1-byte only at a time. How to handle delay after -byte transfer only.Code:uint8_t buf[8] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}; void get_data(uint8_t buf[]) { for ( i = 0; i < sizeof(buf); i+=2 ) { send_data(uint8_t buf); __delay_us(5); //only after transferring -bytes. } // loop should transfer total 8 bytes. __delay_us(100); }
Please rectify the code.
sizeof(buf) won't work, as the function actually receives a pointer, and does not know the buffer size. You need to pass the buffer size to the function along with the buffer itself.
Question 6.4
Ok. Will do. What about the loop? How to handle delay after 2-byte transfer only and as send_data sends one byte at a time, and not two. Please rectify.
I meant the function "get_data()" should be called "send_data()", if that's what it is doing.
The function "exchange8bit()" should be called perhaps "send_byte()", if that is what it is doing.
If you want to send two bytes, perhaps you should call the "send_byte()" function twice. And you need to fix the function call, as the part in parenthesis is not right.Code:uint8_t buf[8] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}; void send_data(uint8_t buf[], int size) { for ( /* ... */ ) { send_byte(uint8_t buf); __delay_us(5); } }
Again, I'm not completely sure what that inner function is supposed to be doing, so let us know if it is doing something other than sending a data byte.
Ok. fine. send_byte will send 1-byte only. once 2-bytes are sent one after other delay func will be called. This way all 8-bytes needs to be transferred.
One more thing, __delay_us(5) should be given only at 2,4,6 bytes transfer. After 8 bytes delay is different.
As long as you want that last delay to be longer, then your example in post #18 is fine. After the last two bytes are sent, the (5) delay is called and then the (100) delay is called, which just add to an approximate delay of 105 us.
Hi Matticus.. thanks for the help. I am able to achieve this.
I have one more question, I have declared a variable in a function in a .c file as
extern volatile uint8_t *new_data;
The same has been declared before main function which is in different file as
uint8_t *new_data;
When I compile I get this error
Conflicting declarations for variable "_new_data".
What could be the reason?
If I change both places *new_data to new_data[]....it works.
Of course it conflicts, one is volatile, one isn't.
volatile uint8_t *new_data;