Part Number: TMS320F280049C
Tool/software: Code Composer Studio
hi, in my project I set the processor as master and I use a hi-6138 module as a slave.
To set the slave device, I need to write and read some values in the registers of the sensor. I can see the data I sent with the help of an oscilloscope, but I cannot read any meaningful data (reading 0x0000) because this is why I need to read while initializing the device. so if I can't do the reading function correctly, I can't initialize the sensor.
here are my spi settings
/* SPI Pins:
* 57: CS
* 56: CLK
* 8: MOSI
* 17: MISO
* */
GPIO_setMasterCore(8, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_8_SPISIMOA);
GPIO_setMasterCore(17, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_17_SPISOMIA);
GPIO_setMasterCore(56, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_56_SPICLKA);
GPIO_setAnalogMode(57, GPIO_ANALOG_DISABLED);
GPIO_setPadConfig(57, GPIO_PIN_TYPE_STD);
GPIO_setDirectionMode(57, GPIO_DIR_MODE_OUT);
void spiSetup(void)
{
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_SPIA);
/* Disable Module */
SPI_disableModule(SPIA_BASE);
/* SPI Configuration */
SPI_setConfig(SPIA_BASE,
DEVICE_LSPCLK_FREQ,
SPI_PROT_POL0PHA0 ,
SPI_MODE_MASTER,
500000,
8);
/* Enable FIFO */
SPI_enableFIFO(SPIA_BASE);
/* Reset FIFOs */
SPI_resetRxFIFO(SPIA_BASE);
SPI_resetTxFIFO(SPIA_BASE);
/* Set FIFO Levels */
SPI_setFIFOInterruptLevel(SPIA_BASE, SPI_FIFO_TX1,
SPI_FIFO_RX1); // 1 YERİNE 3
/* Clear Interrupts */
Interrupt_register(INT_SPIA_RX, &spiRxFIFOISR);
SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP6);
SPI_enableModule(SPIA_BASE);
EINT;
ERTM;
}
and register writes function code:
unsigned char Write_6131LowReg(unsigned char reg_number, unsigned short data, unsigned char irq_mgmt) {
unsigned short i;
//unsigned short dummy;
volatile unsigned short bufferTX[2];
bufferTX[0] = (data); // upper data byte 4800
bufferTX[1] = data<<8; // lower data byte
// Assert SPI chip select
GPIO_writePin(57,0);
// Send 8-bit SPI op code = 0x80 + reg_number
SPI_writeDataNonBlocking(SPIA_BASE,((0x80 + reg_number)<<8));
while(SPI_isBusy(SPIA_BASE)){}
DEVICE_DELAY_US(5);
// Read and discard received data char in Rx buffer
dummym1 = SPI_readDataNonBlocking(SPIA_BASE);
// transmit 2 data bytes
for (i = 0; i < 2; i++) {
// transmit next byte
SPI_writeDataNonBlocking(SPIA_BASE,bufferTX[i]);
while(SPI_isBusy(SPIA_BASE)){}
DEVICE_DELAY_US(5);
// Read and discard received data char in Rx buffer
dummym = SPI_readDataNonBlocking(SPIA_BASE);
}
// negate slave chip select
while(SPI_isBusy(SPIA_BASE)){}
DEVICE_DELAY_US(25);
GPIO_writePin(57,1); // faster than PIO_Set(pinNss);
return('P');
}
and read register function code
unsigned short Read_6131LowReg(unsigned char reg_number, unsigned char irq_mgmt) {
unsigned short i;
// Assert SPI chip select
GPIO_writePin(57,0);
// Send 8-bit SPI op code = reg_number << 2
SPI_writeDataNonBlocking(SPIA_BASE,(reg_number << 10));
while(SPI_isBusy(SPIA_BASE)){}
DEVICE_DELAY_US(5);
// Read received data char in Rx buffer, discard/overwrite below
bufferRX[0] = SPI_readDataNonBlocking(SPIA_BASE);
// receive 2 bytes register data, transmit 2 dummy data bytes
for (i = 0; i < 2; i++)
//SEND dummy data
SPI_writeDataNonBlocking(SPIA_BASE,0xFFFF);
while(SPI_isBusy(SPIA_BASE)){}
DEVICE_DELAY_US(5);
bufferRX[i] = SPI_readDataNonBlocking(SPIA_BASE);// & 0xFF;
}
while(SPI_isBusy(SPIA_BASE)){}
DEVICE_DELAY_US(25);
GPIO_writePin(57,1);
data = (unsigned int)bufferRX[0] << 8;
data |= (unsigned int)(bufferRX[1]&0x00ff);
return data;
}
I can't find where I made a mistake. I had to add some delay (to complete the communication) during the communication. but still it didn't work. I use Gpio57 as the CE pin and set it as gpio (not as spiaste). and the enable pin stays low throughout the clock, there is no error in the scope view.
HELP PLEASE...
