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.

PGA460-Q1: Using 2 PGAs without UART_ADDR value

Part Number: PGA460-Q1
Other Parts Discussed in Thread: PGA460

Hello,

I wrote a code that is working with 2 PGA and 1 PIC microprocessor. I tried seperately both of them, these works with SPI1 and SPI2 excellent. But when I want to use 2 PGAs at the same time, it always gives 5.78mm distance. I looked  DEV_STAT0 and DEV_STAT1 values for both of them but it didnt give any error. When I use one PGA and run diagnotistics, frequency is 42,55kHz, decay period is 4080, temperature is 32, noise level is 5. But when I use two PGAs and run diagnotistics,  frequency is 5kHz, temperature is 32, noise level is 1. What is the problem? 

I changed the code's SPI parts for use 2 PGAs. You can see parts of my code. 

void pga460_spiTransfer(uint8* mosi, uint8 size )
{
	mmemset16(misoBuft_SPI1, 0x00, sizeof(misoBuft_SPI1)); // idle-low receive buffer data
	mmemset16(misoBuft_SPI2, 0x00, sizeof(misoBuft_SPI2)); // idle-low receive buffer data

	for (int i = 0; i<size; i++)
	{
		misoBuft_SPI1[i] = usscSPI1_transfer(mosi[i]);
	}

	for (int j = 0; j<size; j++)
	{
		misoBuft_SPI2[j] = usscSPI2_transfer(mosi[j]);
	}

}

void pga460_spiMosiIdle(BYTE size)
{		
	for (int i = 0; i<size; i++)
	{
		misoBuf_SPI1[i] = usscSPI1_transfer(0xFF); 
	}
	
	for (int j = 0; j<size; j++)
	{
		misoBuf_SPI2[j] = usscSPI2_transfer(0xFF); 
	}
	
	return;
}

uint8 usscSPI1_transfer(uint8 _data1) {
	mSSP1BUF.reg = _data1;
	while(!SSP1STATbitsBF);
	_regdata1 = mSSP1BUF.reg;
	return _regdata1;
}

uint8 usscSPI2_transfer(uint8 _data2) {
	mSSP2BUF.reg = _data2;
	while(!SSP2STATbitsBF);
	_regdata2 = mSSP2BUF.reg;
	return _regdata2;
}

I sent a data with pga460_spiTransfer function as always, it sends data to 1st PGA and 2th PGA in order. Then, it listens 1st PGA and 2th PGA in order. I know, you are not working with PIC, but I guess you can know working with PGA without UART_ADDR value. 

Apart from these, after calling pga460_spiMosiIdle function, two each register to which misoBuf value is transferred was created for SPI1 and SPI2. You can see a sample below.

double pga460_runDiagnostics(BYTE run, BYTE diag)
{
mmemset16(misoBuf_SPI1, 0x00, sizeof(misoBuf_SPI1));
mmemset16(misoBuf_SPI2, 0x00, sizeof(misoBuf_SPI2));
*
*
*
*
pga460_spiTransfer(pgau4.pga_bufdizi4, sizeof(pga_bufs4));
*
*
*
*
pga460_spiMosiIdle(3);	// MOSI transmit 0xFE to pull MISO return data
		for(int n=0; n<2; n++)
		{
		   diagMeasResult_SPI1[n] = misoBuf_SPI1[n];
		}
		
		for(int m=0; m<2; m++)
		{
		   diagMeasResult_SPI2[m] = misoBuf_SPI2[m];
		}
*
*
*
*
*	
}

  • Hi Lacin,

    To clarify, you have two PGA460 devices connected to one SPI bus? If this is the case, have you updated the address of one of the devices to be different from the other? Note, by default, both devices have a UART_ADDR value of 0. The SPI mode still uses this UART_ADDR value. If both UART_ADDR values are still 0, then the reason SPI communication may be failing is due to data collision from both PGA460 trying to respond simultaneously.

    If you are using two independent SPI ports, such that one SPI port is connected to one PGA460 device, then you don't need to worry about changing the UART_ADDR since the TXD, RXD, and SCLK lines are fully separated per PGA460 device.

  • Hi Akeem,

    I said already I am using 2 different SPI ports for this. 2 different SPI ports for 2 different PGAs. Although, I cant read true values when I use 2 PGAs at the same time. Code works when I use 1 PGA. I sent the code, I want you give advise to me. 

  • Hi Lacin,

    You may need to ensure your MCU can support the use of two SPI ports simultaneously, and that there is no overlap or collision of the processing trying to handle two SPI ports simultaneously. If one SPI port is working properly for one device, there should not be any reason a second independent SPI port for another device wouldn't work. This sounds like a more general PIC SPI question you will need to contact Microchip support about.

    To debug the hardware, I recommend you use an oscilloscope or digital logic analyzer to probe and ensure you are properly generating the master transmitted MOSI commands, that the PGA460 is responding over MISO, and that your SCLK timing is valid for both SPI ports. If the signals are all valid, then it is most likely related to how your SPI ports iare configured on the PIC.

  • Hi Akeem,

    Yes, I solved the problem. It works. Problem was about Checksum. I was delete the unused parts on Calc Checksum function but I was wrong because the received data from pga include checksum value too and parts that is deleted was necessary for received data. It is complately my fault. Sorry for bothering you. 

    But I was wondering which checksum value is not important when I run the GetDistance code? The memory of the PIC processor is not enough, I have to delete the unnecessary parts in the functions.

  • Hi Lacin,

    I'm glad you were able to identify and resolve the problem.

    Regarding the checksum question: 

    Refer to "Table 3 - UART Interface Command List" to see which commands are response commands and which are no-response commands. In the S-TO-M DATA BYTES column, whenever you see "0", this is a no-response command, such as CMDs 0, 1, 2, 3, 4, 10, 12, 14, and 16. Only the no-response commands require the master generated commands, with the one exception of CMD 9, which is the only response command that requires a master generated checksum.