1
Discussion - Software / LibMPSSE - unexpected behavior of SPI_ReadWrite function
« on: March 07, 2022, 01:10:01 PM »
Hello,
SPI_ReadWrite sends unexpected 0xCC, 0xCC and reads data from SPI slave correctly. Then, even on the second call, SPI_Write sends 0xCC. I think there is a problem in LibMPSSE. How fix it?
Code: [Select]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* OS specific libraries */
#ifdef _WIN32
#include<windows.h>
#endif
/* Include D2XX header*/
#include "ftd2xx.h"
/* Include libMPSSE header */
#include "libMPSSE_spi.h"
uint8 wr_buffer[128];
uint8 rd_buffer[128];
uint32 preneseno = 0;
int main()
{
FT_HANDLE handle = NULL;
FT_STATUS status = FT_OK;
FT_DEVICE_LIST_INFO_NODE devList = {0};
ChannelConfig channelConf = {0};
uint32 channels = 0;
uint8 i = 0;
channelConf.ClockRate = 800000;
channelConf.LatencyTimer = 1;
channelConf.configOptions = 0x0020;
channelConf.Pin = 0xFEFBFEFB;
/* init library */
#ifdef _MSC_VER
Init_libMPSSE();
#endif
status = SPI_GetNumChannels(&channels);
if (status != FT_OK) {
printf("status != FT_OK");
return 0;
}
printf("Number of available SPI channels = %d\n",(int)channels);
if (channels > 0)
{
for (i = 0;i < channels;i++)
{
status = SPI_GetChannelInfo(i, &devList);
if (status != FT_OK) {
printf("status != FT_OK");
return 0;
}
if (strcmp("Mila 5000 B", devList.Description) == 0) {
//device is connected
status = SPI_OpenChannel(i, &handle);
if(status != FT_OK) {
printf("status != FT_OK");
return 0;
}
break;
}
}
}
if (handle == NULL) {
printf("not opened");
return 0;
}
status = SPI_InitChannel(handle, &channelConf);
if (status != FT_OK) {
printf("status != FT_OK");
return 0;
}
while (1)
{
//write nasledovane read
wr_buffer[0] = 0x90;
status = SPI_Write(handle, wr_buffer, 1, &preneseno, 0x02);
if (status != FT_OK) {
printf("status != FT_OK");
return 0;
}
status = SPI_Read(handle, rd_buffer, 1, &preneseno, 0x06);
//readwrite
wr_buffer[0] = 0x90;
wr_buffer[1] = 0xFF;
status = SPI_ReadWrite(handle, rd_buffer, wr_buffer, 2, &preneseno, 0x06);
}
return 0;
}
SPI_ReadWrite sends unexpected 0xCC, 0xCC and reads data from SPI slave correctly. Then, even on the second call, SPI_Write sends 0xCC. I think there is a problem in LibMPSSE. How fix it?