2023-10-16 07:14 AM
this is code from an Udemy tutorial but i couldn't get the part of 9 bit data transfer with no parity bit can anyone help me to understand that please
2023-10-16 07:27 AM
What part is tripping you up?
With 9 bit no parity, it uses (reads and advances) 2 bytes of the buffer per character.
2023-10-16 07:29 AM
can we talk in google meet then i will be able to explain my problem better it will be great help
2023-10-16 07:35 AM
suppose my data is uint8_t data[5]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF} now the len of my data is 5 so it will be pass as len. Now my loop will iterate 5 times if i am not wrong but the problem is when we cast it into uint16_t *pdata it will take first two item as one now then it will be mask as 9 bits and pTxBuffer will be increment twice and point to next 16 bit. now my confusion is withing 3 iteration my data array will be completed and if we take 0xFFFF and mask it
then the data become 0x1FF how they can be same
2023-10-16 07:40 AM
> suppose my data is uint8_t data[5]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
This data is not 9-bit data.
9-bit data would be stored as an array of uint16_t values.
2023-10-16 07:52 AM
but what is saw in my pc if i cast 8bit array into 16 bit then it became from uint8_t data[5]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF} to {0xFFFF, 0xFFFF, 0x00FF}
2023-10-16 08:45 AM
True but irrelevant. The issue comes from you using a uint8_t array of length 5 to pass 5 parameters of 2 bytes each. Clearly 5 != 10 so, as you mentioned in your previous post, the function will read outside of the bounds of the array.
So fix the problem: declare the array as uint16_t.
2023-10-16 08:49 AM
but in the tutorial i am following they are sending it as uint8_t and it is working properly thats why it is out of my brain
2023-10-16 08:50 AM
i literally want to talk with someone to clear the confusion i am still in confusion since last seven days still no solution i was able to found
2023-10-16 09:00 AM
Then find a tutor or teacher that you're paying. Perhaps find someone who can cover pointers, and data representation in memory
Do you want to send as 9-bit? If so that data has to come from somewhere.
You can't randomly cast a structure, and change it's content. You're just telling the compiler to process the data in memory a different way. The bytes in memory don't change, the size of the structure in bytes doesn't change.
Where the peripheral is adding the parity bit, it takes 8-bits from you and adds it into the 9-bit shift register. If you want to send 9-bits of actual data, it needs to read at least that much from memory, it reads 16-bits as that's the next size up sufficient to do that.
You could send an array of uint16_t
uint16_t data[5]={0x1FF, 0x1FF, 0x1FF, 0x1FF, 0x1FF}