Bugs in CAL SPI for AVR

An area to discuss AVR and Arduino specific problems and examples

Moderator: Benj

Post Reply
654321
Posts: 2
Joined: Tue Jan 02, 2018 1:49 pm
Been thanked: 1 time
Contact:

Bugs in CAL SPI for AVR

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Bugs in CAL SPI for AVR

Post 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 242 times

654321
Posts: 2
Joined: Tue Jan 02, 2018 1:49 pm
Been thanked: 1 time
Contact:

Re: Bugs in CAL SPI for AVR

Post by 654321 »

I'm using Arduino/ATMega328P and ATMega2560.

Post Reply