второй SPI + тесты i2c
This commit is contained in:
parent
bd1ce624a4
commit
261a840f2f
Binary file not shown.
@ -31,7 +31,7 @@ volatile uint16_t counter1=0 ;
|
||||
volatile uint16_t counter2=0 ;
|
||||
|
||||
|
||||
uint16_t sendNow = 0;
|
||||
uint16_t sendNowI2C = 0, sendNowSPI = 0;
|
||||
uint16_t TestADR = 0;
|
||||
uint16_t NByte = 16;
|
||||
uint16_t WriteI2C = 0;
|
||||
@ -47,14 +47,14 @@ void MainTimerBaseTimeoutInc(void)
|
||||
|
||||
uint16_t ArrayForTests[MAX_BUFFER_SIZE] = {0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0};
|
||||
|
||||
uint16_t ArrayMax[256];
|
||||
//uint16_t ArrayMax[256];
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
InitPerif();
|
||||
FRMUartInit();
|
||||
// GD25Q16ETIGR_en();
|
||||
GD25Q16ETIGR_en();
|
||||
// Bl25cm1a_en();
|
||||
//
|
||||
// IDLE loop. Just sit and loop forever (optional):
|
||||
@ -63,37 +63,31 @@ void main(void)
|
||||
{
|
||||
asm (" NOP");
|
||||
|
||||
if(sendNow)
|
||||
if(sendNowI2C)
|
||||
{
|
||||
// Bl25cm1a_write();
|
||||
// GD25Q16ETIGR_write();
|
||||
|
||||
|
||||
if(WriteI2C)
|
||||
{
|
||||
for(Adr = 0; Adr < 255; Adr+=15)
|
||||
{
|
||||
ArrayForTests[0] = Adr;
|
||||
ZD24C02A_write(NByte, ArrayForTests);
|
||||
MainTimerTimeouts=0;
|
||||
while(MainTimerTimeouts<1000);
|
||||
while(!GpioDataRegs.GPADAT.bit.GPIO1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayMax[0] = Adr;
|
||||
NByte = 254;
|
||||
ZD24C02A_read(NByte, ArrayMax);
|
||||
ArrayForTests[0] = Adr;
|
||||
ZD24C02A_read(NByte, ArrayForTests);
|
||||
}
|
||||
sendNow = 0;
|
||||
sendNowI2C = 0;
|
||||
}
|
||||
if(TestADR)
|
||||
|
||||
if(sendNowSPI == 1)
|
||||
{
|
||||
ZD24C02A_test(ArrayForTests);
|
||||
TestADR = 0;
|
||||
GD25Q16ETIGR_write();
|
||||
sendNowSPI = 0;
|
||||
}
|
||||
|
||||
else if(sendNowSPI == 2)
|
||||
{
|
||||
Bl25cm1a_write();
|
||||
sendNowSPI = 0;
|
||||
}
|
||||
|
||||
if(FMSTR_is_enable()) {
|
||||
|
||||
@ -19,35 +19,35 @@
|
||||
#define LID 0b10000010 //Locks the identification page in read-only mode
|
||||
|
||||
|
||||
uint16_t sdata = RDSR; // sent data
|
||||
uint16_t rdata = 0; // received data
|
||||
uint16_t error = 0;
|
||||
uint16_t sdata2 = RDSR; // sent data
|
||||
uint16_t rdata2 = 0; // received data
|
||||
uint16_t error2 = 0;
|
||||
|
||||
void Bl25cm1a_en(void)
|
||||
{
|
||||
transmitData(WREN);
|
||||
while(SpiaRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
transmitBData(WREN);
|
||||
while(SpibRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
rdata = SpiaRegs.SPIRXBUF;
|
||||
rdata2 = SpibRegs.SPIRXBUF;
|
||||
}
|
||||
|
||||
|
||||
void Bl25cm1a_write(void)
|
||||
{
|
||||
transmitData(sdata);
|
||||
transmitBData(sdata2);
|
||||
|
||||
//
|
||||
// Wait until data is received
|
||||
//
|
||||
while(SpiaRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
while(SpibRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
rdata = SpiaRegs.SPIRXBUF;
|
||||
rdata2 = SpibRegs.SPIRXBUF;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -9,24 +9,37 @@
|
||||
|
||||
|
||||
uint16_t sdata1 = 0x6; // sent data
|
||||
uint16_t rdata1 = 0; // received data
|
||||
uint16_t rdata1[256]; // received data
|
||||
uint16_t error1 = 0;
|
||||
|
||||
void GD25Q16ETIGR_en(void)
|
||||
{
|
||||
transmitData(sdata1);
|
||||
while(SpiaRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
transmitBData(sdata1);
|
||||
while(SpibRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
rdata1 = SpiaRegs.SPIRXBUF;
|
||||
rdata1[0] = SpibRegs.SPIRXBUF;
|
||||
}
|
||||
|
||||
|
||||
void GD25Q16ETIGR_write(void)
|
||||
{
|
||||
transmitData(sdata1);
|
||||
uint16_t i;
|
||||
for(i = 0; i<=255; i++)
|
||||
{
|
||||
transmitBData(i);
|
||||
|
||||
//
|
||||
// Wait until data is received
|
||||
//
|
||||
while(SpibRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
{
|
||||
|
||||
}
|
||||
rdata1[i] = SpibRegs.SPIRXBUF;
|
||||
}
|
||||
/* transmitData(0x90);
|
||||
|
||||
//
|
||||
// Wait until data is received
|
||||
@ -35,7 +48,48 @@ void GD25Q16ETIGR_write(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
rdata1 = SpiaRegs.SPIRXBUF;
|
||||
|
||||
transmitData(0xFF);
|
||||
|
||||
//
|
||||
// Wait until data is received
|
||||
//
|
||||
while(SpiaRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
{
|
||||
|
||||
}
|
||||
rdata1 = SpiaRegs.SPIRXBUF;
|
||||
|
||||
transmitData(0xFF);
|
||||
|
||||
//
|
||||
// Wait until data is received
|
||||
//
|
||||
while(SpiaRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
{
|
||||
|
||||
}
|
||||
rdata1 = SpiaRegs.SPIRXBUF;
|
||||
transmitData(0xFF);
|
||||
|
||||
//
|
||||
// Wait until data is received
|
||||
//
|
||||
while(SpiaRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
{
|
||||
|
||||
}
|
||||
rdata1 = SpiaRegs.SPIRXBUF;
|
||||
transmitData(0xFF);
|
||||
|
||||
//
|
||||
// Wait until data is received
|
||||
//
|
||||
while(SpiaRegs.SPIFFRX.bit.RXFFST != 1)
|
||||
{
|
||||
|
||||
}
|
||||
rdata1 = SpiaRegs.SPIRXBUF;
|
||||
*/
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ volatile uint16_t SlaveAdr = I2C_SLAVE_ADDRESS;
|
||||
|
||||
void ZD24C02A_write(uint16_t byteCount, uint16_t * Array)
|
||||
{
|
||||
I2CWrite(SlaveAdr, byteCount, true, Array);
|
||||
I2CWrite(SlaveAdr, (byteCount + 1), true, Array);
|
||||
}
|
||||
|
||||
void ZD24C02A_read(uint16_t byteCount, uint16_t * Array)
|
||||
@ -23,6 +23,13 @@ void ZD24C02A_read(uint16_t byteCount, uint16_t * Array)
|
||||
// I2CWriteReadOnes(I2C_SLAVE_ADDRESS);
|
||||
}
|
||||
|
||||
void ZD24C02A_read_all(uint16_t byteCount, uint16_t * Array)
|
||||
{
|
||||
I2CRead(SlaveAdr, byteCount, true, Array);
|
||||
// I2CWriteRead(I2C_SLAVE_ADDRESS, byteCount, true, Array);
|
||||
// I2CWriteReadOnes(I2C_SLAVE_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
void ZD24C02A_test(uint16_t * Array)
|
||||
{
|
||||
|
||||
@ -15,5 +15,6 @@
|
||||
void ZD24C02A_write(uint16_t byteCount, uint16_t * Array);
|
||||
void ZD24C02A_read(uint16_t byteCount, uint16_t * Array);
|
||||
void ZD24C02A_test(uint16_t * Array);
|
||||
void ZD24C02A_read_all(uint16_t byteCount, uint16_t * Array);
|
||||
|
||||
#endif /* SRC_ZD24C02A_H_ */
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
#define TIME_OVER 1000
|
||||
|
||||
Uint16 TimerTimeouts = 0, ErrI2c = 0, ErrI2c1 = 0, ErrI2c2 = 0, ErrI2c3 = 0, Addr=0, Addr1[255];
|
||||
uint16_t RXdata;
|
||||
uint16_t RXdata, addrCount=0;
|
||||
|
||||
void TimerBaseTimeoutInc(void)
|
||||
{
|
||||
@ -54,7 +54,7 @@ void I2CMasterInit(uint16_t I2C_OwnAddress, uint16_t I2CSlave_Address)
|
||||
// I2C configuration. Use a 400kHz I2CCLK with a 50% duty cycle.
|
||||
//
|
||||
//I2C_initMaster(base, DEVICE_SYSCLK_FREQ, 400000, I2C_DUTYCYCLE_50);
|
||||
I2caRegs.I2CPSC.all = 23; // Prescaler - need 7-12 Mhz on module clk
|
||||
I2caRegs.I2CPSC.all = 88; // Prescaler - need 7-12 Mhz on module clk
|
||||
I2caRegs.I2CCLKL = 0x7; // NOTE: must be non zero
|
||||
I2caRegs.I2CCLKH = 0x8; // NOTE: must be non zero
|
||||
|
||||
@ -135,6 +135,7 @@ void I2CWrite(uint16_t slaveAddr, uint16_t byteCount, bool sendStopCondition, ui
|
||||
//
|
||||
// send Start condition
|
||||
//
|
||||
// I2caRegs.I2CMDR.bit.STP = 0x1;
|
||||
I2caRegs.I2CMDR.bit.STT = 0x1;
|
||||
|
||||
//
|
||||
@ -149,7 +150,7 @@ void I2CWrite(uint16_t slaveAddr, uint16_t byteCount, bool sendStopCondition, ui
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CSTR.bit.BYTESENT != 0x1)&&(TimerTimeouts < TIME_OVER));
|
||||
if(TimerTimeouts >= TIME_OVER) ErrI2c++;
|
||||
|
||||
// else {Addr1[addrCount] = slaveAddr; addrCount++; if(addrCount > 255) addrCount = 0;}
|
||||
//
|
||||
//clear the byte sent
|
||||
//
|
||||
@ -172,8 +173,10 @@ void I2CWrite(uint16_t slaveAddr, uint16_t byteCount, bool sendStopCondition, ui
|
||||
//
|
||||
// Function to read data over I2C. Returns the number of bytes read
|
||||
//
|
||||
uint16_t ttest=0;
|
||||
uint16_t I2CRead(uint16_t slaveAddr, uint16_t byteCount, bool sendStopCondition, uint16_t * I2C_RXdata)
|
||||
{
|
||||
I2caRegs.I2CMDR.bit.NACKMOD = 0x0;
|
||||
//
|
||||
// Configure slave address
|
||||
//
|
||||
@ -185,34 +188,25 @@ uint16_t I2CRead(uint16_t slaveAddr, uint16_t byteCount, bool sendStopCondition,
|
||||
I2caRegs.I2CMDR.bit.MST = 0x1;
|
||||
I2caRegs.I2CMDR.bit.TRX = 0x0;
|
||||
|
||||
//
|
||||
//Set Data Count
|
||||
//
|
||||
I2caRegs.I2CCNT = byteCount;
|
||||
|
||||
//
|
||||
// send Start condition
|
||||
//
|
||||
uint16_t count = 0;
|
||||
if(count == (byteCount-1)) I2caRegs.I2CMDR.bit.NACKMOD = 0x1;
|
||||
|
||||
I2caRegs.I2CCNT = byteCount;
|
||||
I2caRegs.I2CMDR.bit.STT = 0x1;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Read the received data into RX buffer
|
||||
//
|
||||
//
|
||||
// Read the received data into RX buffer
|
||||
//
|
||||
TimerTimeouts = 0;
|
||||
while((count < byteCount)&&(TimerTimeouts < TIME_OVER))
|
||||
while((count < (byteCount))&&(TimerTimeouts < TIME_OVER))
|
||||
{
|
||||
if(I2caRegs.I2CSTR.bit.RRDY ==0x1)
|
||||
{
|
||||
RXdata = I2C_RXdata[count] = I2caRegs.I2CDRR.all;
|
||||
count++;
|
||||
RXdata = I2C_RXdata[count+1] = I2caRegs.I2CDRR.all;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if(TimerTimeouts >= TIME_OVER) ErrI2c2 += (byteCount - count);
|
||||
I2caRegs.I2CMDR.bit.NACKMOD = 0x0;
|
||||
|
||||
//
|
||||
// Send STOP condition
|
||||
@ -423,7 +417,7 @@ void I2CWriteOnse(uint16_t slaveAddr)
|
||||
//
|
||||
// Locals
|
||||
//
|
||||
uint16_t index = 0;
|
||||
//uint16_t index = 0;
|
||||
|
||||
//
|
||||
// Configure slave address
|
||||
|
||||
@ -27,7 +27,7 @@ void InitPerif(void)
|
||||
SdfmGpioInit();
|
||||
SdfmInitEnable();
|
||||
|
||||
SpiaGpioInit();
|
||||
SpiaBGpioInit();
|
||||
I2CMasterGpioInit();
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ void InitPerif(void)
|
||||
PWMAllInit();
|
||||
SdfmInitInterruptEn();
|
||||
SdfmInit(SDFM1);
|
||||
SpiInit();
|
||||
SpiBInit();
|
||||
I2CMasterInit(I2C_OWN_ADDRESS,I2C_SLAVE_ADDRESS);
|
||||
//
|
||||
// Enable global Interrupts and higher priority real-time debug events:
|
||||
|
||||
@ -10,8 +10,12 @@
|
||||
__interrupt void spia_rx_isr(void);
|
||||
__interrupt void spia_tx_isr(void);
|
||||
|
||||
__interrupt void spib_rx_isr(void);
|
||||
__interrupt void spib_tx_isr(void);
|
||||
|
||||
void SpiInit(void)
|
||||
|
||||
|
||||
void SpiAInit(void)
|
||||
{
|
||||
//
|
||||
// Initialize SPI-A
|
||||
@ -72,7 +76,7 @@ void SpiInit(void)
|
||||
SpiaRegs.SPICCR.bit.SPISWRESET = 1;
|
||||
}
|
||||
|
||||
void SpiaGpioInit(void)
|
||||
void SpiaAGpioInit(void)
|
||||
{
|
||||
EALLOW;
|
||||
|
||||
@ -111,7 +115,7 @@ void SpiaGpioInit(void)
|
||||
EDIS;
|
||||
}
|
||||
|
||||
void transmitData(uint16_t a)
|
||||
void transmitAData(uint16_t a)
|
||||
{
|
||||
SpiaRegs.SPITXBUF = a<<8;
|
||||
}
|
||||
@ -129,3 +133,129 @@ __interrupt void spia_tx_isr(void)
|
||||
uint16_t temp = SpiaRegs.SPISTS.all;
|
||||
PieCtrlRegs.PIEACK.all = PIEACK_GROUP6;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void SpiBInit(void)
|
||||
{
|
||||
|
||||
CpuSysRegs.PCLKCR8.bit.SPI_B = 1;
|
||||
|
||||
SpibRegs.SPIFFTX.all = 0xE040;
|
||||
SpibRegs.SPIFFRX.all = 0x2044;
|
||||
SpibRegs.SPIFFCT.all = 0x0;
|
||||
|
||||
//
|
||||
// Initialize core SPI registers
|
||||
//
|
||||
//
|
||||
// Set reset low before configuration changes
|
||||
// Clock polarity (0 == rising, 1 == falling)
|
||||
// 16-bit character
|
||||
// Enable loop-back
|
||||
//
|
||||
SpibRegs.SPICCR.bit.SPISWRESET = 0;
|
||||
SpibRegs.SPICCR.bit.CLKPOLARITY = 0;
|
||||
SpibRegs.SPICCR.bit.SPICHAR = (8 - 1);
|
||||
SpibRegs.SPICCR.bit.SPILBK = 0;
|
||||
|
||||
//
|
||||
// Enable master (0 == slave, 1 == master)
|
||||
// Enable transmission (Talk)
|
||||
// Clock phase (0 == normal, 1 == delayed)
|
||||
// SPI interrupts are disabled
|
||||
//
|
||||
SpibRegs.SPICTL.bit.MASTER_SLAVE = 1;
|
||||
SpibRegs.SPICTL.bit.TALK = 1;
|
||||
SpibRegs.SPICTL.bit.CLK_PHASE = 1;
|
||||
SpibRegs.SPICTL.bit.SPIINTENA = 0;
|
||||
|
||||
PieCtrlRegs.PIEIER6.bit.INTx3 = 0; //3.4.5 PIE Channel Mapping str 150 of trm
|
||||
PieCtrlRegs.PIEIER6.bit.INTx4 = 0;
|
||||
|
||||
PieVectTable.SPIB_RX_INT = &spib_rx_isr;
|
||||
PieVectTable.SPIB_TX_INT = &spib_tx_isr;
|
||||
//
|
||||
// Set the baud rate using a 1 MHz SPICLK
|
||||
// BRR = (LSPCLK / SPICLK) - 1
|
||||
//
|
||||
SpibRegs.SPIBRR.bit.SPI_BIT_RATE = 99;
|
||||
|
||||
// Set FREE bit
|
||||
// Halting on a breakpoint will not halt the SPI
|
||||
//
|
||||
SpibRegs.SPIPRI.bit.FREE = 1;
|
||||
|
||||
//
|
||||
// Release the SPI from reset
|
||||
//
|
||||
SpibRegs.SPICCR.bit.SPISWRESET = 1;
|
||||
}
|
||||
|
||||
void SpiaBGpioInit(void)
|
||||
{
|
||||
EALLOW;
|
||||
|
||||
//
|
||||
// Enable internal pull-up for the selected pins
|
||||
//
|
||||
// Pull-ups can be enabled or disabled by the user.
|
||||
// This will enable the pullups for the specified pins.
|
||||
//
|
||||
GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; // Enable pull-up on GPIO16 (SPISIMOA)
|
||||
GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up on GPIO17 (SPISOMIA)
|
||||
GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Enable pull-up on GPIO18 (SPICLKA)
|
||||
GpioCtrlRegs.GPAPUD.bit.GPIO27 = 0; // Enable pull-up on GPIO19 (SPISTEA)
|
||||
|
||||
//
|
||||
// Set qualification for selected pins to asynch only
|
||||
//
|
||||
// This will select asynch (no qualification) for the selected pins.
|
||||
//
|
||||
GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 3; // Asynch input GPIO16 (SPISIMOA)
|
||||
GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 3; // Asynch input GPIO17 (SPISOMIA)
|
||||
GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3; // Asynch input GPIO18 (SPICLKA)
|
||||
GpioCtrlRegs.GPAQSEL2.bit.GPIO27 = 3; // Asynch input GPIO19 (SPISTEA)
|
||||
|
||||
//
|
||||
// Configure SPI-A pins
|
||||
//
|
||||
// This specifies which of the possible GPIO pins will be SPI functional
|
||||
// pins.
|
||||
//
|
||||
GPIO_SetupPinMux(24, 0, 6);
|
||||
GPIO_SetupPinMux(25, 0, 6);
|
||||
GPIO_SetupPinMux(26, 0, 6);
|
||||
GPIO_SetupPinMux(27, 0, 6);
|
||||
|
||||
// GpioCtrlRegs.GPAMUX1.bit.GPIO24 = 2; // Configure GPIO16 as SPISIMOA
|
||||
// GpioCtrlRegs.GPAMUX1.bit.GPIO25 = 2; // Configure GPIO17 as SPISOMIA
|
||||
// GpioCtrlRegs.GPAMUX1.bit.GPIO26 = 2; // Configure GPIO18 as SPICLKA
|
||||
// GpioCtrlRegs.GPAMUX1.bit.GPIO27 = 2; // Configure GPIO19 as SPISTEA
|
||||
// GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 1; // Configure GPIO16 as SPISIMOA
|
||||
// GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 1; // Configure GPIO17 as SPISOMIA
|
||||
// GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 1; // Configure GPIO18 as SPICLKA
|
||||
// GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 1; // Configure GPIO19 as SPISTEA
|
||||
EDIS;
|
||||
}
|
||||
|
||||
void transmitBData(uint16_t a)
|
||||
{
|
||||
SpibRegs.SPITXBUF = a<<8;
|
||||
}
|
||||
|
||||
|
||||
__interrupt void spib_rx_isr(void)
|
||||
{
|
||||
uint16_t temp = SpibRegs.SPISTS.all;
|
||||
PieCtrlRegs.PIEACK.all = PIEACK_GROUP6;
|
||||
}
|
||||
|
||||
|
||||
__interrupt void spib_tx_isr(void)
|
||||
{
|
||||
uint16_t temp = SpibRegs.SPISTS.all;
|
||||
PieCtrlRegs.PIEACK.all = PIEACK_GROUP6;
|
||||
}
|
||||
|
||||
@ -8,9 +8,11 @@
|
||||
#ifndef SRC_SPI_INIT_H_
|
||||
#define SRC_SPI_INIT_H_
|
||||
|
||||
void SpiaGpioInit(void);
|
||||
void SpiInit(void);
|
||||
void transmitData(uint16_t a);
|
||||
|
||||
void SpiaAGpioInit(void);
|
||||
void SpiAInit(void);
|
||||
void transmitAData(uint16_t a);
|
||||
|
||||
void SpiaBGpioInit(void);
|
||||
void SpiBInit(void);
|
||||
void transmitBData(uint16_t a);
|
||||
#endif /* SRC_SPI_INIT_H_ */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user