# SPI：从设备CRC不匹配，接收到0xA5，期望0x5A

- **ID:** `embedded/spi-crc-mismatch-on-slave`
- **领域:** embedded
- **类别:** protocol_error
- **错误码:** `SPI_ERR_CRC_MISMATCH`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

主设备和从设备之间CRC计算不匹配，原因是多项式设置不同或数据顺序（LSB优先与MSB优先）不一致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| STM32F4 SPI driver v1.4.0 | active | — | — |
| HAL SPI v1.3.2 | active | — | — |

## 解决方案

1. ```
   Align CRC polynomial and bit order on both devices: set `SPI_CR1_CRCPOLY` to the same value (e.g., 0x07) and ensure both use MSB-first by clearing the LSBFIRST bit
   ```
2. ```
   Implement a software CRC check after SPI transfer as a fallback: `if (crc8(data, len) != expected_crc) { retry_transfer(); }`
   ```

## 无效尝试

- **** — Disabling CRC removes error detection, potentially allowing corrupted data to be accepted silently. (60% 失败率)
- **** — Swapping roles does not fix the underlying CRC configuration mismatch; the error will persist on the new master. (90% 失败率)
