I'm doing SPI Bit Banging using PIC16F1718 as slave. I could make it work but only for 1 byte i.e by using char rdata, where rdata is the buffer which stores the incoming bits. so, now i want to use int so that i can store more than 1 byte, but it's giving me errors like:
-> Operator '.' is not applicable to these operands 'rdata'
-> Internal error 'undefined aggregate'
->Internal error 'undefined struct'
I'm attaching my complete working code. I have highlighted the lines with Blue color. Please once have a look and tell me how to use int to make it work.
sbit CE at RB4_bit;
sbit CE_Direction at TRISB4_bit;[COLOR="#0000FF"]unsignedint rdata ;[/COLOR]unsignedchar data_read_flag;int count;unsignedchar i;void main(){
OSCTUNE =0x80;
OSCCON =0b01110010;
RXPPS =0x17;
RC6PPS =0X14;
ANSELA =0x00;//PORT A as Digital
ANSELB =0x00;
ANSELC =0x00;
TRISA =0b00010001;
TRISB =0b00110100;
TRISC =0b10000000;
IOCBN =0X10;//Enable IOC on RB4 -VE Edge of CE
INTCON =0x88;
UART1_Remappable_Init(9600);do{if(data_read_flag ==1){
PORTC.B6= ~PORTC.B6;}}while(1);}void interrupt(){//case for falling edge of CE //IOCBN4_bitif(IOCBN4_bit && IOCBF4_bit && IOCIF_bit)//If RB4 Lower Edge is detected ,IOCBF4_bit is 1{
IOCBP5_bit =1;// enabling interrupt on rising edge of RB5 i.e., CLK
IOCBP.B4=1;// enabling interrupt on rising edge of CE
IOCBN4_bit =0;//Disabling the interrupt on CE -ve Edge
IOCBF4_bit =0;//Disabling RB4 flag bit
IOCIF_bit =0;//Disabling IOC flag bit
count =0;}if(IOCBF5_bit && IOCIF_bit )//If RB5 Rising Edge Detected{
IOCBF5_bit =0;//Disabling RB5 Flag bit
IOCIF_bit =0;//Disabling IOC flag bit
count = count +1;[COLOR="#0000FF"] rdata.B0= PORTA.B0;//Reading Data on RA0 pin[/COLOR]if(count<8){
rdata =(rdata <<1);//shifting the incoming bits to the left}}if( IOCBP4_bit && IOCBF4_bit && IOCIF_bit){
data_read_flag =1;
IOCBP.B4=0;//Disable IOC on Rising Edge of RB4
IOCBP.B5=0;//Disable IOC on Rising Edge of RB5
IOCBN.B4=1;// enabling interrupt for the next transaction
IOCBP4_bit =0;
IOCIF_bit =0;
UART1_Remappable_Write(rdata );}}
There are no bitbang in PIC16 and PIC18.
Try this:
rdata = PORTA & 1;
And for the future. Bitbang is a different thing, not applicable to this bit-oriented operations.