SPI communication- Bit Banging

General discussion on mikroPascal PRO for ARM.
Post Reply
Author
Message
RAJPUT VIDISHA
Posts: 9
Joined: 15 Jul 2015 09:25

SPI communication- Bit Banging

#1 Post by RAJPUT VIDISHA » 29 Jun 2016 06:28

Hi,

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;
unsigned int rdata ;
unsigned char data_read_flag;
int count;
unsigned char 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_bit

if(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;
rdata.B0 = PORTA.B0; //Reading Data on RA0 pin
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 );

}
}


Regards
Vidz

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: SPI communication- Bit Banging

#2 Post by lana.arsic » 29 Jun 2016 13:53

Hi Vidisha,

I believe I have answered you on the ticket.

Best regards,
Lana

Post Reply

Return to “mikroPascal PRO for ARM General”