Skip to content

Bit shifting causing intermittent bit corruption #29

@sdhunna21

Description

@sdhunna21

https://github.com/trinamic/TMC-API/blob/3da0cec86d2f14c3f1b6f29950df6fe2cc41624b/tmc/ic/TMC5160/TMC5160.c#L53

Sometimes when reading a spi value the upper 16 bits are all 1's. I noticed this line of code and changed it like so and the problem was resolved.

Shifting bits with types smaller than the shift can cause undefined behavour. At least on our processor, the msp430 it needs this fix.

	uint32_t v[5] = {0};
	for (uint32_t i = 0; i < 5; i++) {
		v[i] = data[i];
	}

	uint32_t value = (v[1] << 24) | (v[2] << 16) | (v[3] << 8) | (v[4]);
	return value;
	```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions