I think that are several bugs in CAL SPI for AVR in Flowcode 7.3.0.5 and maybe you could check.
1. When you set Prescale to Fosc/64 you will come to the code in AVR_CAL_SPI.c with MX_SPI_PR_SCALE_X == 64 and set it to 2 but now a few lines down, you will have another match for MX_SPI_PR_SCALE_X == 2 and set it to 4. Because only the last 2 bits set the clock rate on the chip which are now 00 in fact you set the clock to Fosc/4.
Code: Select all
#if MX_SPI_CHANNEL_X > 0
#if MX_SPI_PR_SCALE_X == 4
#undef MX_SPI_PR_SCALE_X
#define MX_SPI_PR_SCALE_X 0
#endif
#if MX_SPI_PR_SCALE_X == 16
#undef MX_SPI_PR_SCALE_X
#define MX_SPI_PR_SCALE_X 1
#endif
#if MX_SPI_PR_SCALE_X == 64
#undef MX_SPI_PR_SCALE_X
#define MX_SPI_PR_SCALE_X 2
#endif
#if MX_SPI_PR_SCALE_X == 128
#undef MX_SPI_PR_SCALE_X
#define MX_SPI_PR_SCALE_X 3
#endif
#if MX_SPI_PR_SCALE_X == 2
#undef MX_SPI_PR_SCALE_X
#define MX_SPI_PR_SCALE_X 4
#endif
#if MX_SPI_PR_SCALE_X == 8
#undef MX_SPI_PR_SCALE_X
#define MX_SPI_PR_SCALE_X 5
#endif
#if MX_SPI_PR_SCALE_X == 32
#undef MX_SPI_PR_SCALE_X
#define MX_SPI_PR_SCALE_X 6
#endif
#endif
3. AVR support double speed rate so for Fosc/2, Fosc/8 and Fosc/32 you should set SPI2X bit in SPSR register. Somthing like this maybe ?
Code: Select all
SPCR = SPIConfig; //Pass config settings to SPI register
#if (MX_SPI_PR_SCALE_X > 3)
SPSR = 0x01;
#endif