Hi eevblog,
I bought a TransistorTester similar to T4 (but not identical, LCR-T4) awhile ago but the LCD is broken and I tried to replace it with Nokia 5110 (PCD8544). Markus's version supports Nokia 5110 so I flash the board with ComponentTester-1.33m but it's not working. By the way, I am new to avr so there will be mistakes.
Hardware:
//---------------
//TransistorTester/ComponentTester T4 Clone with PCD8544
//Atmega328 8MHz
//PCD8544 (bit-bang SPI)
//---------------
//Nokia 5110:
//1: VCC - 3.3V
//2: GND - GND
//3: SCE - GND
//4: RST - 10K - PD4 (2)
//5: D/C - 10K - PD3 (1) - Data/Command
//6: DN(MOSI) - 10K - PD5 (9)
//7: SCLK - 10K - PD2 (32)
//8: LED - 100R - 5V
// Note: it does not work when RST=PD0, and DIN=PD1, PD0 and PD1 are serial RX and TX, maybe that is the reason
display config-<MCU>.h default remark
328
/RES LCD_RES PD4 optional
/SCE LCD_SCE GND optional
D/C LCD_DC PD3
SCLK LCD_SCLK PD2
SDIN LCD_SDIN PD5
Later on I also added a serial port interface to try to figure out what is wrong.
Files changed:
Makefile - No change
config.h:
Line 082: uncomment #define HW_REF25 to enable hardware reference
Line 307: comment out #define SW_PROBE_COLORS to diable color coding
Line 396: uncomment #define UI_SERIAL_COPY
Line 406: uncomment #define UI_SERIAL_COMMANDS
Line 689: uncomment #define SERIAL_HARDWARE
config_328.h:
Line 099: uncomment #if 0 .. #endif ;to disable LCD_ST7565R
Line 203: change to #if 1 ;to enable LCD_PCD8544 or comment it out
Line 209: change to PD4
Line 210: comment out #define LCD_SCE ;since this is connected to GND
Line 213: change to PD5
Clones - No change
variables.h - No change so far
At present, after writing the firmware with avrdude to ATMega328P, I push the blue test button. A short push, the back light on LCD turns on, so there is power, but nothing on the screen. Voltage measured 5.05V at the ISP programming port, ~3V at LCD. Serial port shows "Component Tester v1.33m". Once the button is up, it's off. I am not sure if this is normal or maybe POWER_CTRL(PD6) is not working properly.
A long push, back light turns on, nothing on the LCD, serial port shows "Component Tester v1.33m" and after a short while "No component found!". I think this means EEPROM is working and the logic of the firmware is being followed.
To help figure out things, I modified main.c so I can test individual components of the firmware and the hardware:
#if defined(__AVR_ATmega328__)
#if (CPU_FREQ != 8000000)
#error <<< KK: Error CPU FREQ is not 8MHz >>>
#endif
#ifndef LCD_PCD8544
#error <<< KK: Error LCD is not PCD8544 >>>
#endif
#ifdef SPI_HARDWARE
#error <<< KK: Error using SPI hardware instead of bitbang >>>
#endif
#ifndef SPI_BITBANG
#error <<< KK: Error not using SPI bitbang >>>
#endif
#if (SPI_SCK != PD2)
#error <<< KK: Error SPI_SCK != PD2 >>>
#endif
#if (SPI_MOSI != PD5)
#error <<< KK: Error SPI_MOSI != PD1 >>>
#endif
#if (POWER_CTRL != PD6)
#error <<< KK: Error POWER_CTRL != PD6 >>>
#endif
#if (TEST_BUTTON != PD7)
#error <<< KK: Error TEST_BUTTON != PD7 >>>
#endif
#ifndef HW_SERIAL
#error <<< KK: Error serial port (HW) is off >>>
#endif
#ifdef SERIAL_RW
#error <<< KK: Error serial port (RW) is on >>>
#endif
#ifdef HW_TOUCH
#error <<< KK: Error touch support is on >>>
#endif
#ifndef LCD_SPI
#error <<< KK: SPI for LCD is off >>>
#endif
#define KK_DEBUG
#define KK_DEBUG_OVERRIDE
#else
#error <<< KK: Configuration Error >>>
#endif
void KK_Debug1(void)
{
//KK: 100Hz toggle PD1
DDRD = (1 << PD1); //Make PORTD1 an output pin by setting it to 1
while(1) //infinite loop
{
PORTD = (1 << PD1); //Turns ON LED at PD1 by setting it 5V
_delay_ms(5); //5ms delay
PORTD= 0x00; //Turns OFF All LEDs
_delay_ms(5); //5ms delay
}
}
void KK_Debug2(void)
{
//KK: serial: output A to Z
uint8_t cc = 65;
Serial_Setup();
while(1) //infinite loop
{
Serial_WriteByte(cc);
_delay_ms(50); //50ms delay
cc++;
if (cc>90) cc=65;
}
}
void KK_Debug3(void)
{
//KK: LCD: output A to Z
uint8_t cc;
LCD_BusSetup(); /* set up LCD bus */
LCD_Init(); /* initialize LCD and clears the LCD*/
UI.LineMode = LINE_STD; /* reset next-line mode */
while(1) //infinite loop
{
LCD_Clear(); /* display was initialized before */
cc = 65;
while(cc<91) {
LCD_Char('X');
_delay_ms(50); //50ms delay
cc++;
}
_delay_ms(2000); //2s delay
}
}
void KK_Serial_WriteBits(uint8_t cc)
{
uint8_t i=0;
while(i<8)
{
if (cc & (1<<i))
Serial_WriteByte('1');
else
Serial_WriteByte('0');
i++;
}
Serial_WriteByte('b');
Serial_WriteByte('\r');
Serial_WriteByte('\n');
}
void KK_Debug4(void)
{
//KK: LCD: output A to Z
uint8_t cc, bb;
Serial_Setup();
LCD_BusSetup(); /* set up LCD bus */
LCD_Init(); /* initialize LCD and clears the LCD*/
UI.LineMode = LINE_STD; /* reset next-line mode */
while(1) //infinite loop
{
LCD_Clear(); /* display was initialized before */
cc = 65;
bb = DDRD;
KK_Serial_WriteBits(bb); //1 is output, so DDRD should be 00111100b, hardware serial is used so bit 0 and 1 is probably ignored
while(cc<91) {
LCD_Char(cc);
_delay_ms(50); //50ms delay
cc++;
}
_delay_ms(2000); //2s delay
}
}
void KK_Debug_SW(void)
{
KK_Debug4();
}
/* ************************************************************************
* the one and only main()
* ************************************************************************ */
/*
* main function
*/
int main(void)
{
uint8_t Test; /* test value */
uint8_t Key; /* user feedback */
#if defined (HW_REF25) || ! defined (BAT_NONE)
uint16_t U_Bat; /* voltage of power supply */
uint32_t Temp; /* some value */
#endif
#ifdef KK_DEBUG_OVERRIDE
KK_Debug_SW();
#endif
/*
* init hardware
*/
The code above replaces the beginning of the main function. So the #error's are tested after config.h and config_328.h are loaded and there is no unexpected configuration errors as far as I can tell since make compiles the code just fine. I used KK_Debug1(), to test all the pins that I modified to make sure the connections are good. Frequency measurement of the output measured 100Hz, so 328P is running at 8MHz. KK_Debug2() showed serial port is working but KK_Debug3() and KK_Debug4() is not working - nothing is displayed on the LCD. Serial output of KK_Debug4() showed DDRD is 00111100b. This, I think, showed the port direction are probably configured. To make sure LCD is connected correctly, I tested it with examples that come with Adafruit_PCD8544 library in ArduinoIDE. It displays animated smiles correctly.
So now I am stuck and I need help with what to do next.
Thanks.
edited: typo last paragraph disabled -> displayed