Address: http://www.cnblogs.com/yanhc/archive/2008/08/22/2175269.html
I recently participated in the adi udc (University Design Competition) competition to debug the touch screen. I used BF533. After debugging the SPI for half a day, I asked Yiqi, But I replied with a barrier, later I asked about the DSP technical support of Adi in China. They also debugged myCode, Really responsible, it turns out that I didn't add ssync (); this statement.
However, there is still a problem with the touch screen, and BF533 cannot communicate with it currently.
// ** File: SPI. h
// ** Target: ADSP-BF533
// ** Creat time:
# Ifndef _ spi_h
# DEFINE _ spi_h
# Define spi_sel_low * pspi_flg & = ~ 0x2000 // spisel5 CLR
# Define spi_sel_high * pspi_flg | = 0x2000 // spisel5 set
// SPI interface funtion
Void spi_init (void );
// SPI send a word Function
Void spi_send_data (unsigned short data );
// SPI receive a word Function
Unsigned short spi_receive_data (void );
# Endif
// ** File: SPI. c
// ** Target: ADSP-BF533
// ** Creat time:
# Include <ccblkfn. h>
# Include <cdefbf533.h>
# Include "sys_func.h"
// SPI interface funtion
Void spi_init (void)
{
* Pspi_baud = (unsigned short) (getsclk ()/(2x10000000); // 5 MHz
// SPI enable, master mode, cpha = 1 (control by software ),
// 16 bit, start transfer with write of spi_tdbr
* Pspi_ctl = 0x5501;
* Pspi_flg = 0xff20; // spisel5 Enabled
}
// SPI send a word Function
Void spi_send_data (unsigned short data)
{
* Pspi_tdbr = data;
While (* pspi_stat & 0x0001) = 0 );
}
// SPI receive a word Function
Unsigned short spi_receive_data (void)
{
Spi_send_data (0 xFFFF );
Return (* pspi_rdbr );
}