I am a long time user of the TC1 tester and I have been lurking and reading this topic for a long time. The usual story, I killed 2 of them before I understood their limitations and have been happily using a third one for several years. All on the stock manufacturers firmware. I finally decided I want the
real firmware and pulled out the 2 dead ones to see if they can be rebuilt.
One is the early version TC1 with a transformer (Unit 1) and the other has the FNIRSI-4A10 board (Unit 2) but luckily both have real ATmega324PA chips in TQFP-44 packages. So while I wait for the replacement/upgrade 644 chips and other improved components to arrive I have been removing the STC15L104W chips, added programming headers and have been compiling and loading a variety of firmware. This has been going well until I tried to switch to H/W SPI today.
I know the pin assignments on both of these are wrong for hardware SPI but I plan to rewire them and I can't even get it to compile without errors. It looks like Feliciano had this exact problem way back in February 2024:
A slightly smaller firmware size
I'm for it. So let's do the 1.51m exercise again (32980B vs X) and please help me troubleshoot my configuration. I enabled
SPI_HARDWARE both on config and config_644, and disabled SPI_BITBANG on the first. I thought that would be enough for the Make, but I get the following errors:
SPI.c: In function 'SPI_Clock':
SPI.c:388:10: error: 'SPCR' undeclared (first use in this function)
Bits = SPCR; /* get control register */
^
SPI.c:388:10: note: each undeclared identifier is reported only once for each function it appears in
SPI.c:389:19: error: 'SPR1' undeclared (first use in this function)
Bits &= ~((1 << SPR1) | (1 << SPR0)); /* clear clock rate bits */
^
SPI.c:389:33: error: 'SPR0' undeclared (first use in this function)
Bits &= ~((1 << SPR1) | (1 << SPR0)); /* clear clock rate bits */
^
SPI.c:406:18: error: 'SPI2X' undeclared (first use in this function)
Bits = (1 << SPI2X); /* set bit to double SPI speed */
^
SPI.c:409:3: error: 'SPSR' undeclared (first use in this function)
SPSR = Bits; /* update register */
^
SPI.c: In function 'SPI_Setup':
SPI.c:444:3: error: 'SPCR' undeclared (first use in this function)
SPCR = (1 << SPE) | (1 << MSTR);
^
SPI.c:444:16: error: 'SPE' undeclared (first use in this function)
SPCR = (1 << SPE) | (1 << MSTR);
^
SPI.c:444:29: error: 'MSTR' undeclared (first use in this function)
SPCR = (1 << SPE) | (1 << MSTR);
^
SPI.c:450:10: error: 'SPSR' undeclared (first use in this function)
Bits = SPSR; /* read flag */
^
SPI.c:451:10: error: 'SPDR' undeclared (first use in this function)
Bits = SPDR; /* clear flag by reading data */
^
SPI.c: In function 'SPI_Write_Byte':
SPI.c:469:3: error: 'SPDR' undeclared (first use in this function)
SPDR = Byte; /* start transmission */
^
SPI.c:470:12: error: 'SPSR' undeclared (first use in this function)
while (!(SPSR & (1 << SPIF))); /* wait for flag */
^
SPI.c:470:25: error: 'SPIF' undeclared (first use in this function)
while (!(SPSR & (1 << SPIF))); /* wait for flag */
^
make.exe: *** [SPI.o] Error 1
> Process Exit Code: 2
I'm a hardware hobbyist and have to struggle a bit when coding and compiling. But with some googling and a lot of trial and error I finally got it to compile. But I am sure my method is wrong and far from ideal!
I had to add the following to the beginning of the SPI.c file:
#include <avr/io.h>
/* local includes */
#include "config.h" /* global configuration */
#ifndef SPCR
#define SPCR SPCR0
#define SPSR SPSR0
#define SPDR SPDR0
#define SPE SPE0
#define MSTR MSTR0
#define SPR0 SPR00
#define SPR1 SPR10
#define SPIF SPIF0
#define SPI2X SPI2X0
#endif
#ifndef SPI_SS
#define SPI_SS PB4 /* Hardware Slave Select pin for ATmega324PA */
#endif
#ifndef SPI_MOSI
#define SPI_MOSI PB5 /* Hardware MOSI pin for ATmega324PA */
#endif
#ifndef SPI_SCK
#define SPI_SCK PB7 /* Hardware SCK pin for ATmega324PA */
#endif
I have been using WinAVR and thought I had upgraded gcc but have just realised I am using an old version:
C:\Electronics\Transistor tester\Software\No2_ComponentTester-1.57m>avr-gcc --version
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_1752) 5.4.0
I could use some advice.
Are the compile errors due to the old gcc version?
Should I try to upgrade my WinAVR toolchain or is there another toolchain you recommend that will work with hardware SPI?
Many thanks to madires, indman, Yuriy_K and all the other who have contributed over the years to this excellent tool!