2009-08-21 10:09 PM
SPI CRC initial value
2011-05-17 04:19 AM
Just starting to use this micro and I don't see a way to change the init values for CRC calculation on SPI.
They are initialized to 0x0000 and the registers are read only. I'd prefer to be able to move the blind spot from 0s. Am I missing something?2011-05-17 04:19 AM
Maybe you can take a look at my post:
There you find a snippet of the SPI initialisation phase. I didn't try it myself though. But maybe a good starting point to let the bells ring and solve your zeros problem. cheers Guy2011-05-17 04:19 AM
Thanks for the response.
That SD card SPI project doesn't appear to use the hardware CRC. There is a software CRC16-CCITT function, but it still uses init value of 0. I can always calculate CRC in code, but it'd be a shame to not use the HW that already exists and is much faster.2011-05-17 04:19 AM
Hey,
Yes I saw it too like this:Quote:
_crc16 = spi_txrx(0xff) << 8; _crc16 |= spi_txrx(0xff); calc_crc = crc16(buf, len); if (_crc16 != calc_crc) { printf(''%s, crcs differ: %04x vs. %04x, len:%i\n'', __func__, _crc16, calc_crc, len); return -1; } Apparently the 0xFF cmd is used to get hardware CRC value calculated and it's based on a zero init. I don't know what the specs are saying on hardware CRC for SD cards. Maybe it's just not possible to alter the CRC init. Maybe there are some differences between SD and not SD or even SDHC. I didn't look in any of these specs. The only thing I know is that it's hard sometimes to filter the necessary information out of these specs. A friend of mine ones did the init procedure in assembler and he search quit a lot to get trough it. Maybe this is something suited for an SD card forum but I did quick googling and found nothing that points in that low level direction. I also know that secure part of SD is quit held hidden and specs are only available by paying a fee. What is the reason actually that you want the change this anyway ? Cheers Guy [ This message was edited by: guyvo67 on 12-08-2009 18:11 ]2011-05-17 04:19 AM
Sorry for late response.
The place where the crc is initialized is actually in crc16()Code:
u16 crc16(const u8 *p, int len) { int i; u16 crc = 0; for (i=0; i<len; i++) crc = crc16_ccitt(crc, p[i]); return crc; } Here you can see that the 1st one is initialized to 0. But it doesn't matter anyway because I want to use the hardware CRC calculation. The application is not with an SD card, but with another part of the product we are working on. We can always have a preset 1st word to ''initialize'' the CRC calculation, but it's really a work around. The reason I want to change is from 0x0000 is to get rid of the blind spot of all 0s. If init value is 0, the CRC for a message that contains only 0s is still 0. So that means that a non-functioning slave will not cause a CRC error. There are several ways to avoid this, but the simplest one to me is hardware CRC check.2011-05-17 04:19 AM
Ok I get the picture now thanks.
Indeed CRC calc with init and content all 0s will give OK cheers Guy