Hello, everyone, This is zhen.
Firstly, Sorry for my bad English.
I am really new to beagle-board-xm and SPI programming.
I searched/googled a lot about this topic and it seems the documentation related to beagleboard SPI programming is very limited.(I found some topics about how to get SPI work, but that is not what i am looking for)
This is why I open a tread and I hope that I could get some helps from you guys.
My project is use the beagle-board-xm SPI interface to control another board.(beagle-board-xm as master)
To do that , the program involves sending a byte out, reading 4 bytes(results) from the result register,deactivating Reset, and reactivating Reset again
I wrote a program to sent a byte based on the Spitest.c i found online.
This is how i send a byte(opcode) to another board and catch the return byte.
uint8_t Send_1byte_to_gp21(uint8_t gp21_opcode_byte)
{
disable reset
uint8_t tx[] = {gp21_opcode_byte,}
uint8_t rx[ARRAY_SIZE(tx)] = {0, };
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx,
.rx_buf = (unsigned long)rx,
.len = ARRAY_SIZE(tx),
.delay_usecs = 50,
.speed_hz = speed,
.bits_per_word = bits,
};
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 1)
pabort(“can’t send spi message”);
puts("");
enable reset
return rx[0];
}
This is how i read a 32 bits result from the result register,
I send out the opcode-address first
then i start reading the result from the 32 bits register.
This method of reading is based on another board,
since i could not find any example programs about beagleboard SPI.
I have little confidence to see it works.
Please share with me if you have a better way of doing it.
`
uint32_t gp21_read_4bytes(uint8_t read_opcode_address)
{
uint32_t Read_result=0;
uint8_t temp;
disable reset
temp=Send_1byte_to_gp21(read_opcode_address);
temp=Send_1byte_to_gp21(0xFF);
Read_result |=temp;//read
Read_result =Read_result<<8;
`
As for the deactivating the Reset pin, I was thinking to use GPIO command to do it.
This is the code i found for ST32 Micro-processor. I did not figure out how to do it yet in beagle-board.
I hope that beagle-board may have a similar command like this which enables me to control the Reset pin easily.
GPIO_WriteBit(GPIOB,GPIO_Pin_12,Bit_RESET)
Also,I hope to put certain delay between each command.
I search for hours to find a sample programs in beagle-board to implement delays and did not find anything.
I am sure that those are the most straight forward question in SPI programming, maybe this is the reason why I did not find any thread about this.
Please share the knowledge if you know the answers, I can certain that there are many other beginners like me who will benefit a lot from you.
Thanks you for reading this,
Again Sorry for my English.