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.
Hi Dears.
I have in hands the EXP430FR5739 with CC3000. So, how i need to use I2C, i`m trying to change the SPI that makes communication with CC3000. Originally was used the UCB0 but is the same for i2C that i will use.., than i change the SPI Code to use the UCA0. PINS P2.0 for MOSI, P2.1 for MISO and P1.5 for CLK, the CS and POWER_EN still the same....BUT..something is wrong, i cant initialize the module, the wires is very confident and checked with Original Code UCB0 and was OK !. Below the changes that was made. Please, some good soul to help me ?
SPI.h
==================================
#define MOSI_MISO_PORT_SEL P2SEL1
#define MOSI_MISO_PORT_SEL2 P2SEL0
#define SPI_MISO_PIN BIT0
#define SPI_MOSI_PIN BIT1
#define SPI_CLK_PORT_SEL P1SEL1
#define SPI_CLK_PORT_SEL2 P1SEL0
#define SPI_CLK_PIN BIT5
#define SPI_IRQ_PORT P2IE
#define SPI_IFG_PORT P2IFG
#define SPI_IRQ_PIN BIT3
SPI.C
======================================
int init_spi(void)
{
// Select the SPI lines: MISO/MOSI on P1.6,7
MOSI_MISO_PORT_SEL |= (SPI_MISO_PIN + SPI_MOSI_PIN);
MOSI_MISO_PORT_SEL2 &= (~(SPI_MISO_PIN + SPI_MOSI_PIN));
//CLK on P2.2
SPI_CLK_PORT_SEL |= (SPI_CLK_PIN);
SPI_CLK_PORT_SEL2 &= ~SPI_CLK_PIN;
UCA0CTLW0 |= UCSWRST; // Put state machine in reset
UCA0CTLW0 |= (UCMST+UCSYNC+UCMSB); // 3-pin, 8-bit SPI master
// Clock polarity high, MSB
UCA0CTLW0 |= UCSSEL_2; // ACLK
UCA0BR0 = 0x02; // /2 change to /1
UCA0BR1 = 0; //
UCA0CTLW0 &= ~UCSWRST; //Initialize USCI state machine
return(ESUCCESS);
}
void SpiWriteDataSynchronous(unsigned char *data, unsigned short size)
{
while (size)
{
while (!(TXBufferIsEmpty()));
UCA0TXBUF = *data;
while (!(RXBufferIsEmpty()));
UCA0RXBUF;
size --;
data++;
}
}
void SpiReadDataSynchronous(unsigned char *data, unsigned short size)
{
long i = 0;
unsigned char *data_to_send = tSpiReadHeader;
for (i = 0; i < size; i ++)
{
while (!(TXBufferIsEmpty()));
//Dummy write to trigger the clock
UCA0TXBUF = data_to_send[0];
while (!(RXBufferIsEmpty()));
data[i] = UCA0RXBUF;
}
}
void SpiReadHeader(void)
{
SpiReadDataSynchronous(sSpiInformation.pRxPacket, 10);
}
long SpiReadDataCont(void)
{
long data_to_recv;
unsigned char *evnt_buff, type;
//determine what type of packet we have
evnt_buff = sSpiInformation.pRxPacket;
data_to_recv = 0;
STREAM_TO_UINT8((char *)(evnt_buff + SPI_HEADER_SIZE), HCI_PACKET_TYPE_OFFSET,
type);
switch(type)
{
case HCI_TYPE_DATA:
{
// We need to read the rest of data..
STREAM_TO_UINT16((char *)(evnt_buff + SPI_HEADER_SIZE),
HCI_DATA_LENGTH_OFFSET, data_to_recv);
if (!((HEADERS_SIZE_EVNT + data_to_recv) & 1))
{
data_to_recv++;
}
if (data_to_recv)
{
SpiReadDataSynchronous(evnt_buff + 10, data_to_recv);
}
break;
}
case HCI_TYPE_EVNT:
{
// Calculate the rest length of the data
STREAM_TO_UINT8((char *)(evnt_buff + SPI_HEADER_SIZE),
HCI_EVENT_LENGTH_OFFSET, data_to_recv);
data_to_recv -= 1;
// Add padding byte if needed
if ((HEADERS_SIZE_EVNT + data_to_recv) & 1)
{
data_to_recv++;
}
if (data_to_recv)
{
SpiReadDataSynchronous(evnt_buff + 10, data_to_recv);
}
sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT;
break;
}
}
return (0);
}
void SpiPauseSpi(void)
{
SPI_IRQ_PORT &= ~SPI_IRQ_PIN;
}
void SpiResumeSpi(void)
{
SPI_IRQ_PORT |= SPI_IRQ_PIN;
}
void SpiTriggerRxProcessing(void)
{
// Trigger Rx processing
SpiPauseSpi();
DEASSERT_CS();
// The magic number that resides at the end of the TX/RX buffer (1 byte after
// the allocated size) for the purpose of detection of the overrun. If the
// magic number is overwritten - buffer overrun occurred - and we will stuck
// here forever!
if (sSpiInformation.pRxPacket[CC3000_RX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER)
{
while (1)
;
}
sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
sSpiInformation.SPIRxHandler(sSpiInformation.pRxPacket + SPI_HEADER_SIZE);
}
#pragma vector=PORT2_VECTOR
__interrupt void IntSpiGPIOHandler(void)
{
switch(__even_in_range(P2IV,P2IV_P2IFG3))
{
case P2IV_P2IFG3:
if (sSpiInformation.ulSpiState == eSPI_STATE_POWERUP)
{
//This means IRQ line was low call a callback of HCI Layer to inform
//on event
sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED;
}
else if (sSpiInformation.ulSpiState == eSPI_STATE_IDLE)
{
sSpiInformation.ulSpiState = eSPI_STATE_READ_IRQ;
/* IRQ line goes down - we are start reception */
ASSERT_CS();
// Wait for TX/RX Compete which will come as DMA interrupt
SpiReadHeader();
sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT;
SSIContReadOperation();
}
else if (sSpiInformation.ulSpiState == eSPI_STATE_WRITE_IRQ)
{
SpiWriteDataSynchronous(sSpiInformation.pTxPacket,
sSpiInformation.usTxPacketLength);
sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
DEASSERT_CS();
}
break;
default:
break;
}
}
void
SSIContReadOperation(void)
{
// The header was read - continue with the payload read
if (!SpiReadDataCont())
{
// All the data was read - finalize handling by switching to the task
// and calling from task Event Handler
SpiTriggerRxProcessing();
}
}
long TXBufferIsEmpty(void)
{
return (UCA0IFG&UCTXIFG);
}
long RXBufferIsEmpty(void)
{
return (UCA0IFG&UCRXIFG);
}
Dears,
I Found the problem, P2.0 and P2.1 are used to UART, i changed now to UCA1 and solve the problem. :)
**Attention** This is a public forum