Reading Switch data on a CFA635

PeteG

New member
I have worked out how to write to the display and got the CRC working, but am still unable to read any switch data. Has anybody else managed to do this? I read the first switch press packet correctly but then I am getting two further packets with 00 command codes, which I should not get from the CFA635 according to the data sheet. After that the CFA635 locks up and wont respond or let me write to the display.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

PeteG

New member
I have got it working now. The main problem was the UART on my PIC was overflowing and shutting down and some timing issues. You can get round this by adding the "ERRORS" option to the #use rs232 directive. This resets the uart if it shuts down. Although you might not need this once the code is working correctly, it will be difficult to get it working without it. Also you will need to add some delay between reading each byte, about 10mS seems to work OK. Tha data sheet is a bit vague on reading switch data packets, so here it is in simpler form; you get 3 bytes after a switch press, 1. 0x80 2, 0x01-length of data which is always 1, 3, the data code for the relavant switch press. Note there is not a CRC on report or acknowledgement packets from the CFA635.

#use rs232 (baud=115200, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=LCD)//ERRORS option prevents UART shutdown on overflow

if (kbhit(LCD)) {
//note no CRC on key activity report
input_buffer_1=getc(LCD);//128=0x80, key activity
delay_ms(10);//must have a delay here
if (kbhit(LCD)) {
input_buffer_2=getc(LCD);//1=0x01, data length, always 1
}
delay_ms(10);//must have a delay here
if (kbhit(LCD)) {
input_buffer_3=getc(LCD);//switch data
}
 
USB LCD Displays - Graphic and Character LCDs with a Keypad
Top