Page 1 of 1

Bugs in CAL SPI for AVR

Posted: Tue Jan 02, 2018 1:55 pm
by 654321
Hi,

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
2. In FC_CAL_SPI_Master_Init_ for Channel 1 you have the line SPIConfig |= (MX_SPI_PR_SCALE_X & 0x07); which use 3 bits for mask, but the clock rate is set with only 2 bits, so I think it should be SPIConfig |= (MX_SPI_PR_SCALE_X & 0x03);
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

Re: Bugs in CAL SPI for AVR

Posted: Wed Jan 03, 2018 4:50 pm
by Benj
Hello,

Many thanks for letting us know. I've had a bit of a re-work and hopefully have solved the issues now.

Certainly I've fixed problem 1.

The other problems you mentioned could be more target device related. Which specific target device are you using and I will explore further.

Simply copy the attached file into your "Flowcode 7/CAL/AVR" folder.
AVR_CAL_SPI.c
(15.53 KiB) Downloaded 243 times

Re: Bugs in CAL SPI for AVR

Posted: Wed Jan 03, 2018 5:34 pm
by 654321
I'm using Arduino/ATMega328P and ATMega2560.