小弟最近在用J5148做开发,用到SPI功能,想先看看时钟的,总是出不来,麻烦各位前辈帮小弟看看。谢谢!
下面是我用到的相关函数和说明,感觉自己思维定式了。(内容有点长哈,麻烦了)
JN5148的SPI配置函数
vAHI_SpiConfigure(uint8 u8SlaveEnable,
bool_t bLsbFirst,
bool_t bPolarity,
bool_t bPhase,
uint8 u8ClockDivider,
bool_t bInterruptEnable,
bool_t bAutoSlaveSelect);
参数含义:
u8SlaveEnable Number of extra SPI slaves to control. Valid values are 0 to 4, higher values are truncated to 4
bLsbFirst Enable/disable data transfer with the least significant bit (LSB) transferred first:TRUE - enable,FALSE - disable
bPolarity Clock polarity:FALSE - unchanged,TRUE - inverted
bPhase Phase: FALSE - latch data on leading edge of clock
TRUE - latch data on trailing edge of clock
u8ClockDivider Clock divisorin the range 0 to 63 - 16-MHz clock is divided by 2 x u8ClockDivider, but 0 is a special value used when no
clock division is required (to obtain a 16-MHz SPI bus clock)
bInterruptEnable Enable/disable interrupt when an SPI transfer has completed:
TRUE - enable
FALSE - disable
bAutoSlaveSelect Enable/disable automatic slave selection:
TRUE - enable
FALSE - disable
SPI从机选择函数:
vAHI_SpiSelect(uint8 value);
SPI从机不选中函数:
vAHI_SpiSelect(uint8 value);
SPI主机发送数据函数:
vAHI_SpiStartTransfer(uint8 u8CharLen, uint32 u32Out);
第一个参数是发送数据的位数,第二个参数是待发送的数据。
SPI等待数据发送完成:
vAHI_SpiWaitBusy(void);
我在5148单片机程序中用一个软件定时器,每秒钟进入计时结束的处理函数中,这个测试过没问题
,然后我把SPI发送数据的过程放在这个处理函数中,示波器也设置成边沿触发了,还是看不到时钟
信号的波形,下面是SPI的初始化操作:
vAHI_SpiConfigure( 1,
E_AHI_SPIM_MSB_FIRST,
E_AHI_SPIM_TXPOS_EDGE,
E_AHI_SPIM_RXPOS_EDGE,
1,
E_AHI_SPIM_INT_DISABLE,
E_AHI_SPIM_AUTOSLAVE_DSABL);
vAHI_SpiSelect(E_AHI_SPIM_SLAVE_ENBLE_1);//E_AHI_SPIM_SLAVE_ENBLE_1);
下面是每秒计时结束的处理函数:
OS_TASK(Timer)
{
vAHI_SpiSelect(E_AHI_SPIM_SLAVE_ENBLE_1);
vAHI_SpiStartTransfer(7,0xFF);//7是指发送的数据是8位
vAHI_SpiWaitBusy();
vAHI_SpiStop();
OS_eContinueSWTimer(MyTimer,16000000,NULL);//继续下次计时
} |