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]; } * * * * * }