Other Parts Discussed in Thread: CC2540
Hello, i'm trying to get the CC2540 to communicate with a ENC28J60(Microchip) ethernet controller using SPI (USART1,Alternative 2).
To make this work i would like to see the /CS and CLK pins change at my oscilloscope when i write to the U1DBUF using the ENC28J60_SPI_TX(data) function.
When I use the IAR debugger all the registers adjusted by halENC28J60_SPI_Init() are set properly.
The problem is the moment i execute the statement
U1DBUF = x;
the register U1DBUF remains 0x00 and U1CSR.TX_BYTE is set immediately,
i suspected it would first send the byte and once that's completed, U1CSR.TX_BYTE would become = 1
Anyway only the /CS pin changes during the ENC28J60_SPI_TX() function, can some tell me what i'm doing wrong?
Hardware:
CC2540EM + Soc_BatteryBoard
Software:
IAR WB 8.10.3
BLE 1.2 Stack
Program:
/******************************* SimpleBLECentral.c ****************************************
void SimpleBLECentral_Init( uint8 task_id )
{
....
// Initialize SPI interface
halENC28J60_SPI_Init();
....
}
static void simpleBLECentral_HandleKeys( uint8 shift, uint8 keys )
{
(void)shift; // Intentionally unreferenced parameter
if ( keys & HAL_KEY_UP )
{
HalENC28J60_HW_WriteByte(0x11);
}
...
}
/******************************* parts of code from custom made file hal_ENC28J60.c based on hal_lcd.c ****************************************
/**************************************************************************************************
* MACROS
**************************************************************************************************/
/* SPI interface control */
#define ENC28J60_SPI_BEGIN() HAL_IO_SET(HAL_ENC28J60_CS_PORT, HAL_ENC28J60_CS_PIN, 0); /* chip select */
#define ENC28J60_SPI_END() \
{ \
asm("NOP"); \
asm("NOP"); \
asm("NOP"); \
asm("NOP"); \
HAL_IO_SET(HAL_ENC28J60_CS_PORT, HAL_ENC28J60_CS_PIN, 1); /* chip select */ \
}
/* clear the received and transmit byte status, write tx data to buffer, wait till transmit done */
#define ENC28J60_SPI_TX(x) { U1CSR &= ~(BV(2) | BV(1)); U1DBUF = x; while( !(U1CSR & BV(1)) ); }
#define ENC28J60_SPI_WAIT_RXRDY() { while(!(U1CSR & BV(1))); }
/**************************************************************************************************
* FUNCTIONS - API
**************************************************************************************************/
/**************************************************************************************************
* @fn halENC28J60_SPI_Init
*
* @brief Initialise SPI interface needed for ENC28J60 control.
*
* @param None
*
* @return None
**************************************************************************************************/
void halENC28J60_SPI_Init(void)
{
//*********USART1,Alternative 2****************
PERCFG |= 0x02; // PERCFG.U1CFG = 1
P1SEL |= 0xE0; // P1_7, P1_6, and P1_5 are peripherals
P1SEL &= ~0x10; // P1_4 is GPIO (SSN)
P1DIR |= 0x10; // SSN is set as output
// init_Baudrate
//********** Set baud rate to 9600*************
U1BAUD = 0x3B; // BAUD_M = 59
U1GCR &= 0xA0; // Positive clock polarity; MOSI @ __/^^ clk; MSB first
U1GCR |= 0x08; // BAUD_E = 8
// SPI Master Mode
U1CSR &= 0x01;
// Configure phase, polarity, and bit order
U1GCR |= 0x80; // CPOL = 1
U1GCR |= 0x20; // ORDER = 1
P1_4 = 1;
}
/**************************************************************************************************
* @fn HalENC28J60_HW_WriteByte
*
* @brief Write 1 byte to the ENC28J60
*
* @param uint8 data - data to be written to the ENC28J60
*
* @return None
**************************************************************************************************/
void HalENC28J60_HW_WriteByte(uint8 data)
{
ENC28J60_SPI_BEGIN();
ENC28J60_SPI_TX(data);
ENC28J60_SPI_WAIT_RXRDY();
ENC28J60_SPI_END();
}