Dear killzone_kid
Thank you for interesting but I test the following code in ESp32 without any crash or error :
#include "driver/spi_master.h"
#define PIN_NUM_MISO 25
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK 19
#define PIN_NUM_CS 22
esp_err_t ret;
spi_device_handle_t spi;
gpio_config_t io_conf;
spi_bus_config_t buscfg;
spi_device_interface_config_t devcfg;
TaskHandle_t xHandleSlaveTask = NULL;
typedef struct {
unsigned long a1:3;
unsigned long a2:1;
unsigned long a3:1;
unsigned long a4:3;
unsigned long b:8;
unsigned long c:8;
unsigned long d:8;
unsigned long e:4;
unsigned long f:6;
}bitfields;
union data{
unsigned long long i;
bitfields bf;
};
union data x;
void spi_pre_transfer_callback(spi_transaction_t *t)
{
Serial.println("CB");
}
void spi_post_transfer_callback(spi_transaction_t *t)
{
Serial.println("PB");
}
void send_spi_data_packet(void * pvParameters)
{
spi_transaction_t t;
static spi_transaction_t trans;
memset(&t, 0, sizeof(t));
memset(&trans, 0, sizeof(spi_transaction_t));
trans.length=8;
trans.user=(void*)0;
trans.flags=SPI_TRANS_USE_TXDATA;
trans.tx_data[0]=0x2A; //Column Address Set
// while(1)
// {
// ret=spi_device_queue_trans(spi, &trans, portMAX_DELAY);
// assert(ret==ESP_OK);
// vTaskDelay(5 / portTICK_RATE_MS);
// }
//while(1)
{
t.length = 64;
t.tx_buffer = &x.i;
t.user=(void*)0;
ret=spi_device_transmit(spi, &t);
assert(ret==ESP_OK);
vTaskDelay(5 / portTICK_RATE_MS);
}
}
void setup(){
unsigned long long v = 0xefaabbcc6d;
unsigned char y;
BaseType_t xReturned;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = 0b11111;
gpio_config(&io_conf);
buscfg.miso_io_num=PIN_NUM_MISO;
buscfg.mosi_io_num=PIN_NUM_MOSI;
buscfg.sclk_io_num=PIN_NUM_CLK;
buscfg.quadwp_io_num=-1;
buscfg.quadhd_io_num=-1;
devcfg.clock_speed_hz=10000;
devcfg.mode=0;
devcfg.spics_io_num=PIN_NUM_CS;
devcfg.queue_size=7;
devcfg.pre_cb = spi_pre_transfer_callback;
devcfg.post_cb = spi_post_transfer_callback;
x.i = v;
Serial.begin(115200);
printf("sizeof x is %dbytes\n",sizeof(x));
printf("%x %x %x %x %x %x %x %x %x\n", x.bf.a1,x.bf.a2,x.bf.a3,x.bf.a4, x.bf.b, x.bf.c, x.bf.d, x.bf.e, x.bf.f);
printf("0 0x%x\n", *((unsigned char *) &x.i + 0));
printf("1 0x%x\n", *((unsigned char *) &x.i + 1));
printf("2 0x%x\n", *((unsigned char *) &x.i + 2));
printf("3 0x%x\n", *((unsigned char *) &x.i + 3));
printf("4 0x%x\n", *((unsigned char *) &x.i + 4));
printf("5 0x%x\n", *((unsigned char *) &x.i + 5));
printf("6 0x%x\n", *((unsigned char *) &x.i + 6));
//Initialize the SPI bus
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
assert(ret==ESP_OK);
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
assert(ret==ESP_OK);
while(1)
{
send_spi_data_packet(spi);
x.bf.c++;
x.bf.a4--;
printf("%x %x %x %x %x %x %x %x %x %p\n", x.bf.a1,x.bf.a2,x.bf.a3,x.bf.a4, x.bf.b, x.bf.c, x.bf.d, x.bf.e, x.bf.f,&x.i);
}
xReturned = xTaskCreate(&send_spi_data_packet, "send_spi_data_packet", 5 * configMINIMAL_STACK_SIZE, NULL, 5, &xHandleSlaveTask);
if( xReturned != pdPASS )
{
ESP_LOGE ("xTaskCreate", "send_spi_data_packet: %d", xReturned);
}
}
void loop() {
}