Please, anyone here tell me why am i not able to read my MC13192 registers. My System consists of AVR AT90CAN128 MCU and MC13192 transceiver.
Whenever i send some address on MOSI during 1st SPI burst operation, in the two subsequent SPI bursts what i receive on MISO is 0x0000.
Is it that there are only few specific transceiver registers which can be read? Right now, here in this code, i am trying to read the CLKO_Ctl register, 0x0A whose default value happens to be 0x7E86. But my MISO tells its 0x0000. Shall i take it? However, i have tried it with many more different registers.
I am setting my SPI clock frequency to 8 MHz.I hope my transceiver is alive because CLKO is always present there whenever i probe on the CLKO pin.
#include<avr/io.h>
#include<inttypes.h>
#define F_CPU 16000000L /* MCU Clock Speed */
#define SPI_PORT PORTB /* Define SPI port */
#define SS PB0 /* The SPI Slave Select Bit */
uint8_t temp = 0x65; /* initialized to some value. Have no meaning in perticular */
uint16_t Rx_SPI = 0x1234;
uint16_t delay_count;
void delay(uint8_t ms)
{
uint16_t cnt;
asm volatile (
"\n"
"L_dl1%=:" "\n\t"
"mov %A0, %A2" "\n\t"
"mov %B0, %B2" "\n"
"L_dl2%=:" "\n\t"
"sbiw %A0, 1" "\n\t"
"brne L_dl2%=" "\n\t"
"dec %1" "\n\t"
"brne L_dl1%=" "\n\t"
: "=&w" (cnt)
: "r" (ms), "r" (delay_count)
);
}
void MC13192_Reset()
{
PORTD |= (0 << PD7); /* RESET the transceiver by pulling low RESET pin */
DDRD |= (1 << DDD7) | (1 << DDD1) | (1<<DDD0); /* Set Direction register as output */
delay(10); /* Held the line low for 10 milliseconds */
PORTD |= (1 << PD7); /* Pull the RESET high */
delay(25); /* wait for 25 milliseconds untill the Transceiver completely enters the Idle Mode */
}
void SPI_MasterInit(void)
{
/* Set MOSI and SCK and SS as output */
DDRB |= (1<<DDB2)|(1<<DDB1)|(1<<DDB0);
/* Enable SPI, Master, set clock rate fck/16 */
SPCR |= (1<<SPE)|(1<<MSTR);
SPSR |= (1<<SPI2X);
}
void main()
{
uint8_t reg_address = 0;
delay_count = F_CPU/4000;
SPI_MasterInit(); /* Initialize MCU SPI Interface */
MC13192_Reset(); /* RESET the Transceiver */
reg_address = 0x0A; /* Select some register to be read */
reg_address |= 0x80; /* MSB to 1 for reading the register */
SPI_PORT |= (0<<SS); /* Assert the SPI slave select PIN */
/* 1st SPI burst */
SPDR = reg_address; /* Send the register address */
while(!(SPSR &(1<<SPIF))); /* Wait till transmission completes */
temp = SPDR; /* Clear the SPI data register to receive register contents */
/* 2nd SPI burst */
SPDR = 0xFF; /* Send dummy data for receiving register contents*/
while(!(SPSR &(1<<SPIF)));/* Wait till transmission completes */
temp = SPDR; /* Collect higher 8 bits of the register contents */
Rx_SPI = temp; // Assign the received MSB part of 16 bit register
Rx_SPI = Rx_SPI << 8; // contents and left shift the same.
/* 3rd and final SPI burst */
SPDR = 0xFF;/* Send dummy data for receiving register contents*/
while(!(SPSR &(1<<SPIF)));/* Wait till transmission completes */
temp = SPDR;/* Collect lower 8 bits of the register contents */
Rx_SPI = temp;
SPI_PORT |= (1<<SS); /* Deassert the SPI slave select PIN */
while(1); /* Infinite looping */
}