Hey guys, thanks very much for your help
Unfortunately I am still very much stuck on this problem, I've looked at the C and ASM solutions but they still do not seem to solve this problem.
I have read through the datasheets many times, but I think it's a misunderstand on my part of the MAX3100.
What I'm trying to achieve is send a string to the MAX3100 by looping over my 'spi_write' function.
This function outputs two bytes, one after the other. My understanding of SPI and the MAX3100 is when you send the first byte, you get a byte back. Hence in my code, whenever I send a byte, I loop until the buffer contains data, then read it, then repeat the process.
My issue is, I can send the first character, it skips the second, sends the third and skips the forth. The only way I am able to output the full character sequence is add a large looping delay at the bottom of my spi_write function. So hence if i output 'TEST' I get 'TS'
Does anyone know of a nice way to get around these issues I am facing, I've tried using the SPI interrupts, which didn't seem to work, the MAX IRQ line, again which didn't seem to work. I'm at a loss at the moment.
My code is the following with my comments as to how I think it should be working.
Code:
void spi_write(unsigned char txdata1, unsigned char txdata2)
{
unsigned char rxdata, rxdata1, rxdata2;
CS = 0; //chip select
rxdata1 = SSPBUF; //lose data in buffer
SSPBUF = txdata1; //write the first MAX3100 control byte
//0b10000000
while(!STAT_BF); //loop until buffer contains data
rxdata1 = SSPBUF; //retrieve data
SSPBUF = txdata2; //write the second MAX3100 data byte
while(!STAT_BF); //loop until buffer contains data
rxdata2 = SSPBUF; //retrieve data
CS = 1; //de-select chip
}
void spi_puts(const char *str)
{
while(*str){
//putch(*str);
spi_write(0b10000000, *str);
str++;
}
}
If anyone could please take a look at this issue, and shed some light it would be appreciated.
Thanks for your input so far.
Regards
Rich