A question about reusing pins: RC4 is currently connected to a 2.5V voltage reference, and RC5 measures battery voltage via a 1:4 voltage divider, if I also want to use PC4 and PC5 for I2C_SDA and I2C_SCL respectively, would it be possible? And similarly for PD2 and PD3 which I am currently using it as LCD_SCLK and LCD_D/C respectively but I would like to dual use as KEY_INC and KEY_DEC but what modification do I need to make to the circuit?
If you disable the battery monitoring (BAT_NONE), the external voltage reference and the protection relay (both are disabled by default) you can free up PC4 and PC5 for I2C. The increase/decrease push buttons are wired the same way like the rotary encoder (see Karl-Heinz' documentation for the rotary encoder).
I can move battery monitoring and external voltage reference to ADC6 and ADC7 so I can still keep the functions. What about AREF? Was there any reason I couldn't just move external voltage reference to AREF?
How would I use ADC6 and ADC7 or AREF? Do I just change in config_328.h
#define TP_REF PC4 /* test pin with 2.5V reference and relay */
#define TP_BAT PC5 /* test pin with 4:1 voltage divider */
to
#define TP_REF AREF /* test pin with 2.5V reference and relay */
#define TP_BAT ADC6 /* test pin with 4:1 voltage divider */
I haven't make up my mind about using relay or not. I would probably have to keep 2.5V reference voltage at PC4 if I want to use relay since ADC6, 7, and AREF are all input only.
The dual use of increase/decrease push buttons and LCD display, I don't understand how it would work. Does LCD only need to communicate with the 328P when we try to change what is being displayed or does it communicate every times it refreshes? I can see noises on the Nokia 5110 (PCD8544) that is why I think there is some kind of refresh rate. Right now PD2 is connected to LCD_SCLK, but if you look at Table 2.1 and 2.7, the rotary encoders are not connected to LCD_SCLK but instead to other LCD pins. (I think Table 2.2 which has rotary encoder 1 connected to ST7565 STRIP_GRID is behaves completely differently, right?) Do I need to move PD2 to some other LCD pin such as LCD_DN(MOSI)? Another reason I ask is because I have the SCE pin on the LCD tied to the GND, so the LCD is enabled all the time. Doesn't this means that any voltage change on PD2 and PD3 is going to affect the LCD? PD2 and PD3 are currently connected to 10K resistors then to LCD pins, following Figure 2.6 I would need to connect PD2 and PD3 via 10K resistors to 5V. This probably means I need to
5V--10K--|
PD--1K---|--<10K--LCD
|--PUSH_BUTTON--GND
PCD8544 's LCD_Data() calls SPI's SPI_Write_Byte() (bitbang version). And in there it sends data to LCD by calling
SPI_PORT |= (1 << SPI_MOSI);
SPI_PORT &= ~(1 << SPI_MOSI);
which sets PD to either 5V or GND. LCD would see 5V when PD=1 and 0.4V when PD=0, so I think above circuit would work. But what about the problems I discussed earlier:
1) does LCD needs SPI communication all the time?
2) does the pushing the button affect subsequent SPI communication?
3) does the firmware need to query the button and communicate via SPI at the same time? I think long push is only for the Test button not increase/decrease button.
4) do I need to move PD2 from LCD_SCLK to say LCD_DN(MOSI) keep in mind that SCE of PCD8544 is always connected to GND?