This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Read 64 bits from SCIB Buffer



After much help, I was able to write an interrupt driven algorithm to receive a data stream (64bits) that is unparsed into different sections (Sync, ID, command, checksum). However, it is not working. When I try to enter a sample datastream, it only reads the last 4 values (0xCDEF) and that's it.

The code at the moment is looking at CDEF as sync pattern instead of 1234 and I cannot receive any other values to be inserted into other sections of data.

Thanks.

Waqqas

//--- Global Variables
Uint16 AdcBuf[ADC_BUF_LEN];					// ADC buffer allocation
Uint16 DEBUG_TOGGLE = 1;					// Used in realtime mode investigation - Lab 6
Uint32 PwmDuty;								// measured PWM duty cycle
Uint32 PwmPeriod;							// measured PWM period
Uint16 sdataA;    // Send data for SCI-A
Uint64 sdataB;    // Send data for SCI-B
Uint16 rdataA;    // Received data for SCI-A
Uint64 rdataB;    // Received data for SCI-A
Uint16 rdata_pointA; // Used for checking the received data
Uint64 rdata_pointB;
Uint16 number;
Uint16 syncPattern = 0;
Uint16 Sync = 0x1234; //0x7E;          // A constant value which always marks the start of a packet
Uint16 StreamLength = 64;			// Number of bits in payload
char Argument;
unsigned crc = 0;
int checksum = 0;
Uint16 ID;
unsigned char cmd;
unsigned sentCRC;    // Send data for SCI-A
Uint64 DataStream;

   DataStream = 0x1234567890ABCDEF;
   sdataB = DataStream;

__interrupt void scibTxFifoIsr(void)
{
	Uint16 i;
	ScibRegs.SCITXBUF = (sdataB & 0xFF);     // Send data
	ScibRegs.SCITXBUF = ((sdataB | 0xFF) >> 8);   //Sync Pattern (16 bits)
	ScibRegs.SCITXBUF = (sdataB & 0xFF) >> 16;
	ScibRegs.SCITXBUF = (sdataB | 0xFF) >> 24;    // ID (16 bits)
	ScibRegs.SCITXBUF = (sdataB & 0xFF) >> 32;
	ScibRegs.SCITXBUF = (sdataB | 0xFF) >> 40;   // Command (16 bits)
	ScibRegs.SCITXBUF = (sdataB & 0xFF) >> 48;   // Argument (8 bits)
	ScibRegs.SCITXBUF = (sdataB & 0xFF) >> 56;   // CRC8 (8 bits)

	for(i=0; i< 8; i++)
	{
		sdataB = DataStream;				//Increment send data for next cycle
	}
	ScibRegs.SCIFFTX.bit.TXFFINTCLR=1;  // Clear Interrupt flag
	PieCtrlRegs.PIEACK.all|=0x100;      // Issue PIE ACK

}

__interrupt void scibRxFifoIsr(void)
{
//	Uint16 i;
	syncPattern = 0;
	number = 0;
	//	rdataB[i]=ScibRegs.SCIRXBUF.all;
		syncPattern = (ScibRegs.SCIRXBUF.all & 0xFF);
		syncPattern |= (ScibRegs.SCIRXBUF.all & 0xFF) << 8;// Read data

		//while (syncPattern != Sync)

		if (syncPattern == Sync)
		{
			number = 1;

		ID = (ScibRegs.SCIRXBUF.all & 0xFF);
		ID |= (ScibRegs.SCIRXBUF.all & 0xFF) << 8;// Read data

		cmd = (ScibRegs.SCIRXBUF.all & 0xFF) << 16;
		cmd |= (ScibRegs.SCIRXBUF.all & 0xFF) << 24;// Read data

		Argument = (ScibRegs.SCIRXBUF.all & 0xFF);

		sentCRC = (ScibRegs.SCIRXBUF.all & 0xFF);
		checksum = crc8(crc,&cmd, sizeof(cmd));
	//	if (checksum == sentCRC)

		//{
//			print ("Command Good!");

		//}
		}


	ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1;  // Clear Overflow flag
	ScibRegs.SCIFFRX.bit.RXFFINTCLR=1; 	// Clear Interrupt flag
	PieCtrlRegs.PIEACK.all|=0x100;  	// Issue PIE ack
}

void scib_fifo_init()
{
	ScibRegs.SCICCR.all =0x0007;    // 1 stop bit,  No loopback
									// No parity,8 char bits,
									// async mode, idle-line protocol
	ScibRegs.SCICTL1.all =0x0047;//3;   // enable TX, RX, internal SCICLK,
									// Disable RX ERR, SLEEP, TXWAKE
	ScibRegs.SCICTL2.bit.TXINTENA =1;
	ScibRegs.SCICTL2.bit.RXBKINTENA =1;
	ScibRegs.SCIHBAUD    =0x0000;
	ScibRegs.SCILBAUD    =SCI_PRD;
	ScibRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back (Doesnt work on 0)
	ScibRegs.SCIFFTX.all=0xC028;
	ScibRegs.SCIFFRX.all=0x0028;
	ScibRegs.SCIFFCT.all=0x00;

	ScibRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset
	ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;
	ScibRegs.SCIFFRX.bit.RXFIFORESET=1;
	ScibRegs.SCIFFTX.bit.TXFFIL = 0x0008;
	ScibRegs.SCIFFRX.bit.RXFIFORESET=1;

	ScibRegs.SCIFFRX.bit.RXFFINTCLR = 1;
	ScibRegs.SCIFFRX.bit.RXFFINT = 1;
	ScibRegs.SCIFFRX.bit.RXFFOVRCLR = 1;
	ScibRegs.SCIFFRX.bit.RXFFIENA=1;
	ScibRegs.SCIFFRX.bit.RXFFIL = 0x0008;


}

  • Hi Waqqas,

    1st, cmd is only 16 bits and you are trying to write to bits 16-31 in your RXISR.

    2nd, your TXISR should probably be written like ScibRegs.TXBUF = (sdataB >> SHIFT_VALUE) & 0xFF;

    3rd, you don't need the loop below.
    for(i=0; i< 8; i++)
    {
    sdataB = DataStream; //Increment send data for next cycle
    }

    4th, you will not generate a TX interrupt until you have 8 characters in the FIFO. I would not be writing to the FIFO in a TX interrupt. It looks like you don't really need a TX INT in this case. Just use your main loop to write to the TXBUF.

    5th, How are you writing to the TXBUF before entering the TX interrupt routine?

    sal
  • Thanks Sal,
    I got some of the bugs out after following your comments. Looking forward to completely debug the code soon.

    Thanks.

    Waqqas