Bugs in CAL SPI for AVR

An area to discuss AVR and Arduino specific problems and examples

Moderator: Benj

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

Bugs in CAL SPI for AVR

Postby 654321 » Tue Jan 02, 2018 1:55 pm

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
These users thanked the author 654321 for the post:
Benj (Tue Jan 02, 2018 4:28 pm)
Rating: 5.56%
 

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

Re: Bugs in CAL SPI for AVR

Postby Benj » Wed Jan 03, 2018 4:50 pm

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
(16.04 KiB) Downloaded 34 times

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

Re: Bugs in CAL SPI for AVR

Postby 654321 » Wed Jan 03, 2018 5:34 pm

I'm using Arduino/ATMega328P and ATMega2560.